I want to match my string to one sequence or another, and it has to match at least one of them.
For and I learned it can be done with:
(?=one)(?=other)
Is there something like this for OR?
I am using Java, Matcher and Pattern classes.
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.
Generally speaking about regexes, you definitely should begin your journey into Regex wonderland here: Regex tutorial
What you currently need is the
|(pipe character)To match the strings
oneORother, use:or if you don’t want to store the matches, just simply
To be Java specific, this article is very good at explaining the subject
You will have to use your patterns this way:
Please note, there are much more possibilities regarding Matcher then what I displayed here…
Also, I’d highly recommend using online regex checkers such as Regexplanet (Java) or regex101, they make your life a lot easier!