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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:43:08+00:00 2026-06-12T21:43:08+00:00

i am new to regular expressions in Java. I like to extract a string

  • 0

i am new to regular expressions in Java. I like to extract a string by using regular expressions.

This is my String: “Hello,World”

I like to extract the text after “,”. The result would be “World”. I tried this:

final Pattern pattern = Pattern.compile(",(.+?)"); 
final Matcher matcher = pattern.matcher("Hello,World"); 
matcher.find(); 

But what would be the next step?

  • 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-12T21:43:10+00:00Added an answer on June 12, 2026 at 9:43 pm

    You don’t need Regex for this. You can simply split on comma and get the 2nd element from the array: –

    System.out.println("Hello,World".split(",")[1]);
    

    OUTPUT: –

    World
    

    But if you want to use Regex, you need to remove ? from your Regex.

    ? after + is used for Reluctant matching. It will only match W and stop there.
    You don’t need that here. You need to match until it can match.

    So use greedy matching instead.

    Here’s the code with modified Regex: –

    final Pattern pattern = Pattern.compile(",(.+)"); 
    final Matcher matcher = pattern.matcher("Hello,World"); 
    
    if (matcher.find()) {
        System.out.println(matcher.group(1));
    }
    

    OUTPUT: –

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

Sidebar

Related Questions

I am doing some fairly extensive string manipulations using regular expressions in Java. Currently,
am new to regular expressions and i cant handle a regex search using grep..
I'm new to regular expressions and i'm feeling this very difficult to solve: I
I'm new to regular expressions, and have no clue where to start, it's like
Bear with me, as I'm quite new to using regular expressions. I have regexp
prehistory: Java regular expression for binary string I can extract a substring with binary
I'm new to regular expressions in Java (or any language, for that matter) and
I am new to regular expressions. I want to use java's replaceAll() function to
I'm new to regular expressions and java so please bear with my newbish question.
I'm new to regular expressions in Java and I need to validate if a

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.