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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:13:43+00:00 2026-06-13T23:13:43+00:00

I need a help finding java regex pattern to get one query information from

  • 0

I need a help finding java regex pattern to get one query information from the URI.
For instance URI here is

"GET /6.2/calculateroute.xml?routeattributes=sm,wp,lg,bb&legattributes=mn&maneuverattributes=ac,po,tt,le,-rn,-sp,-di,no,nu,nr,sh&instructionFormat=html&language=en_US&mode=fastest;car;traffic:default&waypoint0=37.79548,-122.392025&waypoint1=36.0957717,-115.1745167&resolution=786&app_id=D4KnHBzGYyJtbM8lVfYX&token=TRKB7vnBguWLam5rdWshTA HTTP/1.1"

I need to extract 4 value out of it which I manage to do it:

GET

/6.2/calculateroute.xml

routeattributes=sm,wp,lg,bb&legattributes=mn&maneuverattributes=ac,po,tt,le,-rn,-sp,-di,no,nu,nr,sh&instructionFormat=html&language=en_US&mode=fastest;car;traffic:default&waypoint0=37.79548,-122.392025&waypoint1=36.0957717,-115.1745167&resolution=786&app_id=D4KnHBzGYyJtbM8lVfYX&token=TRKB7vnBguWLam5rdWshTA

HTTP/1.1

Now the question is how do I write a regex for app_id value from the query string. Note app_id do not appear in all the pattern, so it should be generic and regex should not fail if app_id is missing. Please help…

  • 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-13T23:13:44+00:00Added an answer on June 13, 2026 at 11:13 pm

    Your question can be simplified to: “How do I extract an optional query parameter from a string”. Here’s how:

    String appId = input.replaceAll("(.*(app_id=(\\w+)).*)|.*", "$3");
    

    The appId variable will contain the app_id value if it’s present or be blank otherwise.

    Here’s some test code with the code bundled as a utility method:

    public static String getParameterValue(String input, String parameter) {
        return input.replaceAll("(.*("+parameter+"=(\\w+)).*)|.*", "$3"));
    }
    
    public static void main(String[] args) {
        String input1 = "foo=bar&app_id=D4KnHBzGYyJtbM8lVfYX&x=y";
        String input2 = "foo=bar&XXXXXX=D4KnHBzGYyJtbM8lVfYX&x=y";
    
        System.out.println("app_id1:" + getParameterValue(input1, "app_id"));
        System.out.println("app_id2:" + getParameterValue(input2, "app_id"));
    }
    

    Output:

    app_id1:D4KnHBzGYyJtbM8lVfYX
    app_id2:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help in finding out how to get the Fvalue1 from method1 and
I need help finding the second Wednesday of the year. Here is what I
Need help finding or having a RegEx match a MM/YY or MM/YYYY format. My
I need a little help for finding regular expression that suits my need, what
Need help with a query that I wrote: I have three tables Company id
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Need help writing a script downloads data from google insight using c# this is
need help/guide for sql select query, I have 2 table stock and stock_history, in
I need your help in finding the appropriate code for getting the stored users
I need help finding the most efficient way to merge two in-memory collections with

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.