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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:57:15+00:00 2026-06-02T01:57:15+00:00

The Java String class has a matches(String regex) method that checks whether the current

  • 0

The Java String class has a matches(String regex) method that checks whether the current string matches the given regular expression. However, how can we find whether a substring of the current string would match the regular expression?

I am trying to mimic the behavior of grep using Java. grep takes a line and prints all those lines that match the given regular expression anywhere in the line. I am not sure how to do that with Java, because the matches method checks whether the entire line (i.e. string) matches the regex and not any substring within it.

  • 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-02T01:57:18+00:00Added an answer on June 2, 2026 at 1:57 am

    Like ColinD said, your best bet is to read in your strings a line at a time, then run your regex with a reluctant wildcard on both ends.

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

Sidebar

Related Questions

I'd like to add a method AddDefaultNamespace() to the String class in Java so
I wrote a class that has a map of <String, Object> . I need
I was just looking at the implementation of the Java String class's .indexOf() method
What is the easiest way to test (using reflection), whether given method (i.e. java.lang.Method
Why there is no reverse method in String class in Java? Instead, the reverse()
import java.util.regex.*; import java.io.*; class Patmatch{ static String str = ; public static void
Java has string pool, due to which objects of string class are immutable. But
junit.framework.AssertionFailedError: Class com.android.deviceintelligence.test.Testshutdown has no public constructor TestCase(String name) or TestCase() at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at
Having read the documentation of Java's String class, it doesn't appear to support popping
In Java, I'm wondering why the length attribute of the String class isn't private?

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.