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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:21:45+00:00 2026-05-20T20:21:45+00:00

I’m comparing 2 URL query strings to see if they’re equal; however, I want

  • 0

I’m comparing 2 URL query strings to see if they’re equal; however, I want to ignore a specific query parameter (always with a numeric value) if it exists. So, these 2 query strings should be equal:

firstName=bobby&lastName=tables&paramToIgnore=2

firstName=bobby&lastName=tables&paramToIgnore=5

So, I tried to use a regex replace using the REReplaceNoCase function:

REReplaceNoCase(myQueryString, "&paramToIgnore=[0-9]*", "")

This works fine for the above example. I apply the replace to both strings and then compare. The problem is that I can’t be sure that the param will be the last one in the string… the following 2 query strings should also be equal:

firstName=bobby&lastName=tables&paramToIgnore=2

paramToIgnore=5&firstName=bobby&lastName=tables

So, I changed the regex to make the preceding ampersand optional… "&?paramToIgnore=[0-9]*". But – these strings will still not be equal as I’ll be left with an extra ampersand in one of the strings but not the other:

firstName=bobby&lastName=tables

&firstName=bobby&lastName=tables

Similarly, I can’t just remove preceding and following ampersands ("&?paramToIgnore=[0-9]*&?") as if the query param is in the middle of the string I’ll strip one ampersand too many in one string and not the other – e.g.

firstName=bobby&lastName=tables&paramToIgnore=2

firstName=bobby&paramToIgnore=5&lastName=tables

will become

firstName=bobby&lastName=tables

firstName=bobbylastName=tables

I can’t seem to get my head around the logic of this… Can anyone help me out with a solution?

  • 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-20T20:21:46+00:00Added an answer on May 20, 2026 at 8:21 pm

    If you can’t be sure of the order the parameters appear i would recommend, that you don’t compare them by the string itsself.

    I recommend splitting the string up like this:

    String stringA = "firstName=bobby&lastName=tables&paramToIgnore=2";
    String stringB = "firstName=bobby&lastName=tables&paramToIgnore=5";
    
    String[] partsA = stringA.split("&");
    String[] partsB = stringB.split("&");
    

    Then go through arrays and make the paramToIgnore somehow euqal:

    for(int i = 0; i < partsA.length; i++)
    {
      if(partsA[i].startsWith("paramToIgnore"){
       partsA[i] = "IgnoreMePlease";
      }
    }
    
    for(int j = 0; j < partsB.length; j++)
    {
      if(partsB[i].startsWith("paramToIgnore"){
       partsB[i] = "IgnoreMePlease";
      }
    }
    

    Then you can sort and compare the arrays to see if they are equal:

    Arrays.sort(partsA);
    Arrays.sort(partsB);
    boolean b = Arrays.equals(partsA, partsB);
    

    I’m pretty sure it’s possible to make this more compact and give it a better performance. But with comparing strings like you do, you somehow alsways have to care about the order of your parameters.

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

Sidebar

Related Questions

No related questions found

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.