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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:29:36+00:00 2026-06-15T08:29:36+00:00

Using Java, I’m trying to write a regular expression that would parse another regular

  • 0

Using Java, I’m trying to write a regular expression that would parse another regular expression. I want to extract the named groups from the source regular expression (those represent parameters separated by slashes in an URL). Also, the source string may or may not start and end with a slash.

For example, for both source strings :

(?<name>john)/(?<facet>aaa/bbb/ccc/?)

and

/(?<name>john)/(?<facet>aaa/bbb/ccc/?)/

I’d like a regular expression that would extract those as named groups:

(?<name>john) and (?<facet>aaa/bbb/ccc/?)

I tried :

(^|.*/)(?<param>\(\?<[^>]+>[^\)]+\))(/.*|$)

But this only returns (?<name>john) as a group named “param”, not (?<facet>aaa/bbb/ccc/?)!!

When I remove the (/.*|$) part, both are returned! But I want this ending condition to make sure a param is followed by a slash or is at the end of the line…

Do you have any idea why (/.*|$) prevents the second param to be found?

  • 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-15T08:29:38+00:00Added an answer on June 15, 2026 at 8:29 am

    You can use the below regex: –

    "(?:/|^)(\\(\\?<.*?>.*?\\))(?=/|$)"
    

    And use Matcher@find method to extract all the matches.

    String str = "(?<name>john)/***(?<facet>aaa/bbb/ccc/?)/(?<not>aaa/bbb/?)***";
    Matcher matcher = Pattern.compile("(?:/|^)(\\(\\?<.*?>.*?\\))(?=/|$)").matcher(str);
    
    while (matcher.find()) {
        System.out.println(matcher.group(1));
    }
    

    Output : –

    (?<name>john)
    

    The last one is not printed, as it is neither followed by a slash nor end of line.

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

Sidebar

Related Questions

Using Java (1.6) I want to split an input string that has components of
Using java in one process, how can we create another process that is an
Using java I am trying to develop a method using recursion to analyze a
Using Java, how can I detect all of the browsers that are installed on
Using Java, how can I test that a URL is contactable, and returns a
Using Java 1.4.2 with unlimited jurisdiction policy files installed. I have a class that
Using java for Android development. I have an array that stores image resources. The
Using java.net, java.io, what is the fastest way to parse html from online, and
Using Java is there anyway to display a custom form/image that behaves similar to
Using Java over Windows Vista, I'm trying to create a kind of a monitor

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.