Can I use OR in a regular expression without capturing nested ones?

I use rubular.com to create my regular expression, and their documentation describes the following:

(...) Capture everything enclosed (a|b) a or b 

How can I use an OR expression without considering what's in it? Therefore, if I want to combine "a or b followed by c" and only capture c, I cannot use

 (a|b)(c) 

right? Then I commit both "a" and "b" as well as "c". I know that I can filter the results, but it seems like a lot of work ...

Am I missing something obvious? I use this in Java, if appropriate.

+55
regex capture regex-group
Jul 31 '10 at 15:42
source share
3 answers

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

 ((?:a|b)c) 

Here (?:a|b) is a group, but you cannot refer to its correspondence. Thus, you can only refer to a match ((?:a|b)c) , which is either ac or bc .

+91
Jul 31 '10 at 15:45
source share

If your implementation has it, then you can use brackets without jamming:

 (?:a|b) 
+13
Jul 31. '10 at 15:46
source share

Even rubular does not allow parentheses, and priority | low. For example a | bc does not match ccc

+1
Jul 31 '10 at 15:59
source share



All Articles