开发者

Matching multicharacter strings without saving the match in PHP

开发者 https://www.devze.com 2023-04-03 15:55 出处:网络
In PHP using preg_match I want to match one of many multicharacter strings (e.g. \"date\", \"after\" and \"latest\") (followed by some more match, which are saved e.g. ([0-9]+) and the like ).

In PHP using preg_match I want to match one of many multicharacter strings (e.g. "date", "after" and "latest") (followed by some more match, which are saved e.g. ([0-9]+) and the like ).

If it were a single characters (e.g. b, f and g) the regexp would just be:

 /[bfg] rest of the regex(p)?/

If I were to match (and save) the match of multicharacter开发者_JAVA技巧 strings it would be something like:

 /(date|after|latest) rest of the regex(p)?/

Now can I match "date", "after" or "latest" without saving whichever one was matched in the resulting array?


Use non capture group:

 /(?:date|after|latest) rest of the regex(p)?/
0

精彩评论

暂无评论...
验证码 换一张
取 消