我有几行像
The quick brown fox jumps over the lazy dog
quick brown fox jumps over the lazy dog
brown fox jumps over the lazy dog
现在,我想在每个第一个单词之后选择每行的其余部分。即我想标记从一行中第一个单词的末尾开始的所有内容。我的尝试是:
^(?:\w+).*
我在Notepad ++中使用它。为什么要选择整条线?我究竟做错了什么?
感谢您提高我的Regex知识!
^\S+\h+(.+)$
$1
. matches newline
解释:
^ # beginning of line
\S+ # 1 or more non space (you van use \w+ if you want to replace ONLY word characters)
\h+ # 1 or more horizontal spaces
(.+) # group 1, 1 or more any character but newline
$ # end of line
给定示例的结果:
quick brown fox jumps over the lazy dog
brown fox jumps over the lazy dog
fox jumps over the lazy dog
屏幕截图:
这是您的正则表达式的解释:
^ # beginning of line
(?: # start non capture group
\w+ # 1 or more word character
) # end group
.* # 0 or more any character
因此,它匹配一个单词以及该单词之后的所有事物。非捕获组在这里是无用的。非捕获组并不意味着将不匹配,而仅意味着将不被捕获。它严格等同于:^\w+.*
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句