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

The Archive Base Latest Questions

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

I have a regex in Java: Pattern pattern = Pattern.compile(<string>text</string><string>.+</string>); Matcher matcher = pattern.matcher(ganzeDatei);

  • 0

I have a regex in Java:

Pattern pattern = Pattern.compile(<string>text</string><string>.+</string>);
Matcher matcher = pattern.matcher(ganzeDatei);
while (matcher.find()) {
    String string = matcher.group();
    ...

This works fine, but the output is something like

<string>text</string><string>Name</string>

But I just want this: Name

How can I do this?

  • 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-18T00:59:16+00:00Added an answer on May 18, 2026 at 12:59 am

    Capture the text you want to return by wrapping it in parenthesis, so in this example your regex should become

    <string>text</string><string>(.+)</string>
    

    Then you can access the text that matched between the parenthesis with

    matcher.group(1)
    

    The no-arg group method you are calling, returns the entire portion of the input text that matches your pattern, whereas you want just a subsequence of that, which matches a capturing group (the parenthesis).

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

Sidebar

Related Questions

I have the below groovy code import java.util.regex.Matcher; import java.util.regex.Pattern; String myInput=License_All (12313) String
This is our code: import java.io.File; import java.io.FileNotFoundException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern;
Need some regex help in Java. I have a string, which contains text and
final static private Pattern includePattern = Pattern.compile(^\\s+([^\\s]*)); ... Matcher mtest = includePattern.matcher( this.txt); String
If I try this (import java.util.regex.Pattern) (Pattern/compile )!@#$%^&*()) or this (def p #)!@#$%^&*()) I
I'm totally beginner in java. In javascript i have this regex: /[^0-9.,\-\ ]/gi How
I have this regex that uses forward and backward look-aheads: import re re.compile(<!inc\((?=.*?\)!>)|(?<=<!inc\(.*?)\)!>) I'm
I have a problem in applying a regex in my Java code. My text
I have the following regex in Java: private static final String ALPHA_REGEX = [^A-Za-z]+$;
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc

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.