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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:37:11+00:00 2026-05-25T20:37:11+00:00

What would be a convenient and reliable way to extract all the {…} tags

  • 0

What would be a convenient and reliable way to extract all the “{…}” tags from a given string? (Using Java).

So, to give an example:
Say I have: http://www.something.com/{tag1}/path/{tag2}/else/{tag3}.html

I want to get all the “{}” tags; I was thinking about using the Java .split() functions, but not sure what the correct regex would be for this.

Note also: tags can be called anything, not just tagX!

  • 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-25T20:37:12+00:00Added an answer on May 25, 2026 at 8:37 pm

    I would use regular expressions to match this. Something like this could work for your expression:

    String regex = "\\{.*?\\}";
    

    As this will “reluctantly” match any sub string that has { and } surrounding it. The .*? makes it find any character between the { and }, but reluctantly, so it doesn’t match the bigger String:

    {tag1}/path/{tag2}/else/{tag3}
    

    which would be a “greedy” match. Note that the curly braces in the regex need to be escaped with double backslashes since curly braces have a separate meaning inside a regular expression, and if you want to indicate the curly brace String, you need to escape it.

    e.g.,

       public static void main(String[] args) {
          String test = "http://www.something.com/{tag1}/path/{tag2}/else/{tag3}.html";
          String regex = "\\{.*?\\}";
    
          Pattern pattern = Pattern.compile(regex);
          Matcher matcher = pattern.matcher(test);
    
          while (matcher.find()) {
             System.out.println(matcher.group());
          }
       }
    

    With an output of:

    {tag1}
    {tag2}
    {tag3}
    

    You can read more about regular expressions here:
    Oracle Regular Expressions Tutorial

    and for greater detail, here:
    http://www.regular-expressions.info/tutorial

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

Sidebar

Related Questions

I look at a lot of small Java programs. It would be convenient if
Would it be possible to extract the following information from logs? Start up/Shut down
I am creating a multi-plot layout illustration using R, and it would be convenient
What's the best way to call R functionality from within Java? I'm looking for
Possible Duplicate: Capitalize First Char of Each Word in a String Java What would
It would be convenient to be able to specify a class object by its
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I would like to be able to use Spring using setter injection into Scala
It would be really convenient if for certain tasks in org-mode, the subtasks could
Would it be possible to retrieve all the images and video of the providers

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.