Documentation for ?: in regex?

后端 未结 6 716
日久生厌
日久生厌 2020-12-08 14:36

A while ago, I saw in regex (at least in PHP) you can make a capturing group not capture by prepending ?:.

Example

$str = \'big blue b         


        
6条回答
  •  轮回少年
    2020-12-08 14:58

    PHP's preg_match_all uses the PCRE (Perl-Compatible Regular Expression) syntax, which is documented here. Non-capturing subpatterns are documented in the Subpatterns chapter.

    would leave me to believe it has something to do with lookaheads or lookbehinds.

    Nope, there are lots of different features which are triggered by open-bracket-question-mark. Lookahead/lookbehind is just the first one you met.

    It's messy that many options have to be squeezed into (?, instead of given a more readable syntax of their own, but it was necessary to fit everything into a sequence that was previously not a valid expression in itself, in older variants of regex.

提交回复
热议问题