Documentation for ?: in regex?

Olah

New Member
A while ago, I saw in regex (at least in PHP) you can make a capturing group not capture by prepending \[code\]?:\[/code\].Example\[code\]$str = 'big blue ball';$regex = '/b(ig|all)/';preg_match_all($regex, $str, $matches);var_dump($matches);\[/code\]Outputs...\[code\]array(2) { [0]=> array(2) { [0]=> string(3) "big" [1]=> string(4) "ball" } [1]=> array(2) { [0]=> string(2) "ig" [1]=> string(3) "all" }}\[/code\]In this example, I don't care about what was matched in the parenthesis, so I appended the \[code\]?:\[/code\] (\[code\]'/b(?:ig|all)/'\[/code\]) and got output\[code\]array(1) { [0]=> array(2) { [0]=> string(3) "big" [1]=> string(4) "ball" }}\[/code\]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 \[code\]?\[/code\], 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?
 
Back
Top