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

  • Home
  • SEARCH
  • 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 910163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:59:52+00:00 2026-05-15T16:59:52+00:00

I don’t understand why with this regex the method returns false; Pattern.matches(\\bi, an is);

  • 0

I don’t understand why with this regex the method returns false;

Pattern.matches("\\bi", "an is");

the character i is at a word boundary!

  • 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-15T16:59:53+00:00Added an answer on May 15, 2026 at 4:59 pm

    In Java, matches attempts to match a pattern against the entire string.

    This is true for String.matches, Pattern.matches and Matcher.matches.

    If you want to check if there’s a match somewhere in a string, you can use .*\bi.*. In this case, as a Java string literal, it’s ".*\\bi.*".

    java.util.regex.Matcher API links

    • boolean matches(): Attempts to match the entire region against the pattern.

    What .* means

    As used here, the dot . is a regex metacharacter that means (almost) any character. * is a regex metacharacter that means “zero-or-more repetition of”. So for example something like A.*B matches A, followed by zero-or-more of “any” character, followed by B (see on rubular.com).

    References

    • regular-expressions.info/Repetition with Star and Plus and The Dot Matches (Almost) Any Character

    Related questions

    • Difference between .*? and .* for regex

    Note that both the . and * (as well as other metacharacters) may lose their special meaning depending on where they appear. [.*] is a character class that matches either a literal period . or a literal asterisk *. Preceded by a backslash also escapes metacharacters, so a\.b matches "a.b".

    • regular-expressions.info/Character Class and Literal Characters and Metacharacters

    Related problems

    Java does not have regex-based endsWith, startsWith, and contains. You can still use matches to accomplish the same things as follows:

    • matches(".*pattern.*") – does it contain a match of the pattern anywhere?
    • matches("pattern.*") – does it start with a match of the pattern?
    • matches(".*pattern") – does it end with a match of the pattern?

    String API quick cheat sheet

    Here’s a quick cheat sheet that lists which methods are regex-based and which aren’t:

    • Non-regex methods:
      • String replace(char oldChar, char newChar)
      • String replace(CharSequence target, CharSequence replacement)
      • boolean startsWith(String prefix)
      • boolean endsWith(String suffix)
      • boolean contains(CharSequence s)
    • Regex methods:
      • String replaceAll(String regex, String replacement)
      • String replaceFirst(String regex, String replacement)
      • String[] split(String regex)
      • boolean matches(String regex)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.