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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:54:42+00:00 2026-06-09T03:54:42+00:00

I found a regular expression which matches tokens surrounded with {} but it only

  • 0

I found a regular expression which matches tokens surrounded with {} but it only seems find the first found item.

How can the following code be changed so that all of the tokens will be found rather than just {World}, would i need to use loops?

// The search string
String str = "Hello {World} this {is} a {Tokens} test";

// The Regular expression (Finds {word} tokens)
Pattern pt = Pattern.compile("\\{([^}]*)\\}");

// Match the string with the pattern
Matcher m = pt.matcher(str);

// If results are found
if (m.find()) {
    System.out.println(m);
    System.out.println(m.groupCount()); // 1
    System.out.println(m.group(0)); // {World}
    System.out.println(m.group(1)); // World (Get without {})
}
  • 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-09T03:54:43+00:00Added an answer on June 9, 2026 at 3:54 am

    Yes, in your code you just do one match, and get the groups captured in that single match.

    If you want to get the other matches, you have to continue matching in a loop until find() returns false.

    So basically all you need is to replace if with while and you’re there.

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

Sidebar

Related Questions

The following javascript code concatenates the matches found by a regular expression. The regular
I need a regular expression, which catches a first expression. If its not found,
How to write regular expression where we can find all words which are started
I'm looking for a regular expression which matches the following datetime format: dd-MMM-yyyy HH:mm:ss
I found the regular expression for MM/DD/YYYY at http://www.regular-expressions.info/regexbuddy/datemmddyyyy.html but I don't think I
I've found a howto, http://answers.oreilly.com/topic/214-how-to-match-nonprintable-characters-with-a-regular-expression/ , but non of the codes, \e, \x1b, \x1B,
I have found the following regular expression new RegExp((^|\\s)hello(\\s|$)); I refer http://www.javascriptkit.com/jsref/escapesequence.shtml for regular
I began studying Java Regular Expression recently and I found some really intersting task.For
I need a regular expression that would let me validate Url. I found this
Ok, a friend of mine confronted me with a regular expression he found in

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.