Logical Parentheses for regex...?
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
精彩评论