匹配多字符串而不保存PHP中的匹配(Matching multicharacter strings without saving the match in PHP)
在使用preg_match的PHP中,我想匹配许多多字符串中的一个(例如“date”,“after”和“latest”)(后面跟一些更多匹配,例如([0-9] +)等保存) 。
如果它是单个字符(例如b,f和g),则regexp将只是:
/[bfg] rest of the regex(p)?/
如果我匹配(并保存)多字符串的匹配,它将是这样的:
/(date|after|latest) rest of the regex(p)?/
现在我可以匹配“日期”,“之后”或“最新”而不保存结果数组中匹配的那个吗?
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 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?
原文:https://stackoverflow.com/questions/7363559