Strange regular expression difference when using an URL

Hello all,

I took some time and finally was able to come up with a regular expression that express the condition of a parameter in a URL. Baiscally, I want to remove the parameter and everything that belongs to this parameter in the URL so I can construct another link free from this parameter.

I want it to match either a number(todeletetable=10) or a list of numbers seperated with a comma (todeletetable=10,11,12,13,) in the URL

I used the following pattern :

Pattern.compile("&todeletetable=(\\d+,)+&|&todeletetable=\\d+&");

When testing this locally, it works very well.

String toMatch ="method=allocate&todeletetable=153622,153623,153579,&sortDirection=asc"

matcher.replaceAll("&") -> returns"method=allocate&sortDirection=asc"

However, when playing with HTML links, the comma is encoded into %2C. Therefore, I added this expression to the pattern :

Pattern.compile("&todeletetable=(\\d+,)+&|&todeletetable=(\\d+%2C)+&|&todeletetable=\\d+&");

String toMatch ="method=allocate&todeletetable=153622%2C153623%2C153579%2C&sortDirection=asc"

matcher.replaceAll("&") ->returns"method=allocate&sortDirection=asc"

locally but over the web, I get"method=allocate&%2C153623%2C153579%2C&sortDirection=asc"

It seems that the %2C is not detected in the regular expression in the case of an URL. I don't know what to do to avoid this.

Please help me if you can with any hint or solution.

Thank you

Raphas

[1819 byte] By [Raphas2a] at [2007-11-27 3:59:45]
# 1
Use your original pattern but URL decode the URL first using class URLDecoder.P.S. I have not checked your regex BUT it looks over complicated.
sabre150a at 2007-7-12 9:04:18 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you sabre, indeed it worked well.I have changed my pattern to something simpler :"&todeletetable=(\\d+.)*"
Raphas2a at 2007-7-12 9:04:18 > top of Java-index,Java Essentials,Java Programming...