A while ago, I saw in regex (at least in PHP) you can make a capturing group not capture by doing prepending ?:
.
Example
$str = 'big blue ball';
$regex = '/b(ig|all)/';
preg_match_all($regex, $str, $matches);
var_dump($matches);
Outputs...
array(2) {
[0]=>
array(2) {
[0]=>
string(3) "big"
[1]=>
string(4) "ball"
}
[1]=>
array(2) {
[0]=>
string(2) "ig"
[1]=>
string(3) "all"
}
}
In this example, I don't care about what was matched in the parenthesis, so I appended the ?:
('/b(?:ig|all)/'
) and got output
array(1) {
[0]=>
array(2) {
[0]=>
string(3) "big"
[1]=>
string(4) "ball"
}
}
This is very useful - at least I think so. Sometimes you just don't want to clutter your matches with unnecessary values.
I was trying to look up documentation and the official name for this (I call it a non capturing group, but I think I've heard it before).
Being symbols, it seemed hard to Google for.
I have also looked at a number of regex reference guides, with no mention.
Being prefixed with ?
, and appearing in the first chars inside parenthesis would leave me to believe it has something to do with lookaheads or lookbehinds.
So, what is the proper name for these, and where can I learn more?
Thanks
Update
Plenty of answers, thank you! I'll accept an answer in the morning.