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 417319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:34:06+00:00 2026-05-12T18:34:06+00:00

What I need is to check whether a given string partially matches a given

  • 0

What I need is to check whether a given string partially matches a given regex. For example, for the regex ab[0-9]c, the strings “a”, “ab”, “ab3”, and “b3c” would “match”, but not the strings “d”, “abc”, or “a3c”. What I’ve been doing is the clunky a(?:b(?:[0-9](?:c)?)?)? (which only works for some of the partial matches, specifically those which “begin” to match), but since this is part of an API, I’d rather give the users a more intuitive way of entering their matching regexps.

In case the description’s not very clear (and I realize it might not be!), this will be used for validating text input on text boxes. I want to prevent any editing that would result in an invalid string, but I can’t just match the string against a regular regex, since until it’s fully entered, it would not match. For example, using the regex above (ab[0-9]c), when I attempt to enter ‘a’, it’s disallowed, since the string “a” does not match the regex.

Basically, it’s a sort of reverse startsWith() which works on regexps. (new Pattern("ab[0-9]c").startsWith("ab3") should return true.)

Any ideas?

  • 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-05-12T18:34:06+00:00Added an answer on May 12, 2026 at 6:34 pm

    Is Matcher.hitEnd() what you’re looking for?

    Pattern thePattern = Pattern.compile(theRegexString);
    Matcher m = thePattern.matcher(theStringToTest);
    if (m.matches()) {
        return true;
    }
    return m.hitEnd();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to PHP. I need to check whether a given string has
I need check whether a given array will match another array. I can't figure
I need to check whether a given date is in the preceding month for
I need to check whether a string contains any swear words. Following some advice
I need to know whether check whether a String end with something like .xyz
I need to check whether mysql is running or no on a given host.
I need to check programmatically (in .NET) whether a given user (domain account) is
I need to check whether a URL (represented by a NSURL) is available or
In my application I need to check whether device is connected to Internet. I
Ok so basically I need to check,whether in my menu #Container exist any third

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.