perl regex 捕获重复组 [英] perl regex to capture repeating group
本文介绍了perl regex 捕获重复组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个正则表达式,它匹配一行开头的某些内容,然后匹配(并返回)所有其他单词.例如,给定这一行:
I want a regular expression that matches something at the beginning of a line, and then matches (and returns) all other words. For instance, given this line:
$line = "one two three etc";
我想要这样的东西(不起作用):
I want something like this (that doesn't work):
@matches= $line=~ /^one(?:\s+(\S+))$/;
返回到@matches,单词二"、三"、等".
to return into @matches, the words "two", "three", "etc".
我不想知道如何得到这些词.我想用正则表达式来做.看起来很简单,但我一直没能想出解决方案.
I don't want to know how to get the words. I want to do it with a regular expression. It seems so simple, but I have not been able to come with a solution.
推荐答案
^.*?\s\K|(\w+)
试试这个.看演示.
http://regex101.com/r/lS5tT3/2
这篇关于perl regex 捕获重复组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文