开发者

Matching multicharacter strings without saving the match in PHP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜