coldfusion - Struggling with regex logic: how do I remove a param from a url query string? -


I compare the 2 URL query strings and see if they are equal; However, I want to ignore a specific query parameter (always with a numeric value) if it exists. Therefore, these 2 query strings must be the same:

  firstName = bobby & lastname = table & amp; ParamToIgnore = 2 firstName = bobby & lastname = tables and paramToIgnore = 5   

So, I tried to use a regex using the Reffes noises function:

  is again ranked nose (myQueryString, "& paramToIgnore = [0-9] *", "")   

this works fine for the example above. I apply to the place of both the wire and then compare. The problem is that I can not make sure that the ultimate will be in the previous string ... The following 2 query strings should be the same:

  firstName = bobby & lastName = table & amp; ParamToIgnore = 2 paramToIgnore = 5 & amp; FirstName = Bobby & amp; Last Name = tables   

So, I turned regex to make preceding ampersand alternative ... "& paramato ignored = [0-9] *" . But - the string still will not be the same because I will be left with an extra Mprss in a string, but others do not:

  firstName = bobby & lastname = table & amp; firstname = Similarly, I only last  and  the ampersand ( "& paramToIgnore = [0- 9] can not remove the I & ns; bobby & lastname = table  < If the query is in  middle  of the absolute string in the form of / pre> 

* & Amp ;? "), then I will remove too many strips in a string and not the other - E.g.

  First name = Bobby and last name = Table & amp; ParamToIgnore = 2 firstName = bobby & paramToIgnore = 5 & amp; Last name = tables will be   

  first name = Bobby and last name = table first name = BobbyListname = table   

I can not get my head around the argument about this ... can anyone pull me out of the solution?

If you can not make sure about the order, the parameters will appear, T comparison String string A = "first name = Bobby and last name = table and parat to explore = 2"; I suggest dividing the string string like I string string B = "first name = Bobby and last name = table and ultimate-to-unknown = 5"; String [] parts = string asplit ("& amp;"); String [] partsB = stringB.split ("& amp;");

Then go through the arrays and somehow ignore the ultimate euqal:

  (int i = 0; i & lt; PartsA.length; i ++) {if (Parts A [i]. Startswit ("Paratogener") {Parts A [I] = "Undetermine Please";}} for (Int j = 0; J & lt; Parts B. length; J ++) {if (parts b [ii] .Starts ("ParamToIgnore") {partsB [i] = "IgnoreMePlease";}}   

Then you can see it Are they equal: arrays can sort and compare:

  Arrays.sort (partsA); arrays.sort (PartsB); boolean B = arrays.equals (partsA, partsB);   

I'm pretty sure it is possible to do more compact and give it a better performance. But strings like you By comparing, you can somehow take care of the orders of your standards.

Comments