开发者

Logical Parentheses for regex...?

开发者 https://www.devze.com 2022-12-21 01:43 出处:网络
So I am new to regex.... and what I can\'t make sense of is this... How can I search for a specific regex each time in a string, ie match all occurences of \'test\' in a given string.... What could I

So I am new to regex.... and what I can't make sense of is this...

How can I search for a specific regex each time in a string, ie match all occurences of 'test' in a given string.... What could I use as a logical parantheses?

/(test)*/

This returns several matches/Backreferences and doesn't seem to be meant for logically group开发者_开发问答ing/order of execution.


To stop parenthesis from creating match groups, start them with ?:

/(?:test)*/

This just matches "test" several times in a row, without saving the matched substrings anywhere.


Your regex specifies only contiguous occurences of test. For all, you usually need to us a flag to indicate that you wnt to match every occurence, not just the first. In most languages, this is indicated by using the 'g' flag.

/test/g 
0

精彩评论

暂无评论...
验证码 换一张
取 消