Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:14:55+00:00 2026-06-15T07:14:55+00:00

I want to match my string to one sequence or another, and it has

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:14:58+00:00Added an answer on June 15, 2026 at 7:14 am

    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 one OR other, use:

    (one|other)
    

    or if you don’t want to store the matches, just simply

    one|other
    

    To be Java specific, this article is very good at explaining the subject

    You will have to use your patterns this way:

    //Pattern and Matcher
    Pattern compiledPattern = Pattern.compile(myPatternString);
    Matcher matcher = pattern.matcher(myStringToMatch);
    boolean isNextMatch = matcher.find(); //find next match, it exists, 
    if(isNextMatch) {
        String matchedString = myStrin.substring(matcher.start(),matcher.end());
    }
    

    Please note, there are much more possibilities regarding Matcher then what I displayed here…

    //String functions
    boolean didItMatch = myString.matches(myPatternString); //same as Pattern.matches();
    String allReplacedString = myString.replaceAll(myPatternString, replacement)
    String firstReplacedString = myString.replaceFirst(myPatternString, replacement)
    String[] splitParts = myString.split(myPatternString, howManyPartsAtMost);
    

    Also, I’d highly recommend using online regex checkers such as Regexplanet (Java) or regex101, they make your life a lot easier!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to match an alphanumeric string containing at least one letter and one
I want to write a query that will match up a string from one
I am trying to match string which, should contain at least one character which
I want to do a sequence of gsub s against one string, so I
If I want to match() a string with the following pattern: 12345678_12345678 What would
Let's say using Javascript, I want to match a string that ends with [abcde]*
I want to match and modify part of a string if following conditions are
Suppose I want to match abc within the string s only if it occurs
If you have a string with special characters that you want to match with:
In this string: <0> <<1>> <2>> <3> <4> I want to match all instances

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.