I wonder if you can help me with your regex expertise.
I need to write a java method that will have the following signature:
String cleanUrl (String regex, String url)
The method itself will likely be easy - something like
return url.replaceAll(regex, "");
but it doesn't have to be that - you can suggest a different regex processing invocation.
My question has to do more with the regexs I will pass into the method. The regexs need to support 5 different url-cleaning operations:
1) remove specified query params
2) keep specified query params
3) remove all query params
4) just leave the full host
5) just leave the specified number of host components
Examples corresponding to the 5 types above:
Let’s say the url is 1) remove var1 and var 3 -> 2) keep var3 -> 3) remove all -> 4) just leave the host -> 5) just leave 3 host components ->
Any idea how I would write regexs (and the corresponding code) to handle all these while keeping the java code exactly the same for all 5 cases – so only the regex part is different? In other words, the client code should not specify which of the 5 operations I need - all that has to be implicit in the regex and the code in the cleanUrl method.
I need to write a java method that will have the following signature:
String cleanUrl (String regex, String url)
The method itself will likely be easy - something like
return url.replaceAll(regex, "");
but it doesn't have to be that - you can suggest a different regex processing invocation.
My question has to do more with the regexs I will pass into the method. The regexs need to support 5 different url-cleaning operations:
1) remove specified query params
2) keep specified query params
3) remove all query params
4) just leave the full host
5) just leave the specified number of host components
Examples corresponding to the 5 types above:
Let’s say the url is 1) remove var1 and var 3 -> 2) keep var3 -> 3) remove all -> 4) just leave the host -> 5) just leave 3 host components ->
Any idea how I would write regexs (and the corresponding code) to handle all these while keeping the java code exactly the same for all 5 cases – so only the regex part is different? In other words, the client code should not specify which of the 5 operations I need - all that has to be implicit in the regex and the code in the cleanUrl method.