This may be a dumb question, but I couldn’t find it anywhere:
How can I use the java OR regular expression operator (|) without parentheses?
e.g:
Tel|Phone|Fax
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can just use the pipe on its own:
for example:
Output:
The main reason to use parentheses is to limit the scope of the alternatives:
has the same output. but if you just do this:
you get:
because you’ve said “string1” or “2”.
If you don’t want to capture that part of the expression use
?::