tags:

views:

61

answers:

2

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 grouping/order of execution.

+3  A: 

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.

sth
Let me ask this, is there a need for (?: <regex> ) often, in the effect of a logical parentheses?
Zombies
It is worth noting that this construct is specific to Perl (and PCRE-related systems, which most languages can be). Doesn't work in grep, awk, and other POSIX-style regular expression environments.
Michael E
+1  A: 

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 
rampion
I am so new to this, thanks.... also, knowing is half the battle.
Zombies