jucas jucas - 4 months ago 7x
Java Question

How to test if a URL contains certain parameters but not others using regex

I have an url in this format:


I need a regex to match the path and params1 and params2 in any order but if param3 is present then I need it to fail so:

String str1 = "/path?param1=value1&param2=value2"; // This will match
String str2 = "/path?param2=value2&param1=value1"; // This will match
String str3 = "/path?param1=value1&param2=value&param3=value3"; // This will not match

So for I've tried using lookarounds to match the parameters but it is failing:


Any thoughts?

P.D. For the curious I'm trying to match a specific URL from an AndroidManifest.xml file https://developer.android.com/guide/topics/manifest/data-element.html


Try this one out:



If you want the path in as well, then