Can I use an OR in regex without capturing what's enclosed?

可紊 提交于 2019-11-28 03:37:40

Depending on the regular expression implementation you can use so called non-capturing groups with the syntax (?:…):

((?:a|b)c)

Here (?:a|b) is a group but you cannot reference its match. So you can only reference the match of ((?:a|b)c) that is either ac or bc.

If your implementation has it, then you can use non-capturing parentheses:

(?:a|b)

Even rubular doesn't make you use parentheses and the precedence of | is low. For example a|bc does not match ccc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!