fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(a("http://e...content-available-to-author-only...e.com/", new String[] {"foo"}));
  13. System.out.println(a("http://e...content-available-to-author-only...e.com/?foo=bar", new String[] {}));
  14. System.out.println(a("http://e...content-available-to-author-only...e.com/", new String[] {}));
  15. System.out.println(a("http://e...content-available-to-author-only...e.com/?foo=1&bar=2&baz=3", new String[] {"foo", "baz"}));
  16. System.out.println(a("http://e...content-available-to-author-only...e.com/?foo=1&bar=2&baz=3", new String[] {"foo", "bar", "baz"}));
  17. System.out.println(a("http://e...content-available-to-author-only...e.com/?foo&bar=2&baz=", new String[] {"foo", "baz"}));
  18. System.out.println(a("http://e...content-available-to-author-only...e.com/?abc=1&def=2&baz=foo", new String[] {"foo", "bar"}));
  19. System.out.println(a("http://e...content-available-to-author-only...e.com/?foobar=baz", new String[] {"foo"}));
  20. System.out.println(a("http://foo:foo@foo.com:8080/?foo=1&bar=foo", new String[] {"foo"}));
  21. }
  22.  
  23. static String a(String a,String[]b){for(String c:b)a=a.replaceAll("(?<=[?&])"+c+"(=[^&]*)?(&|$)","");return a.replaceAll("[?&]$","");}
  24. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
http://e...content-available-to-author-only...e.com/
http://e...content-available-to-author-only...e.com/?foo=bar
http://e...content-available-to-author-only...e.com/
http://e...content-available-to-author-only...e.com/?bar=2
http://e...content-available-to-author-only...e.com/
http://e...content-available-to-author-only...e.com/?bar=2
http://e...content-available-to-author-only...e.com/?abc=1&def=2&baz=foo
http://e...content-available-to-author-only...e.com/?foobar=baz
http://foo:foo@foo.com:8080/?bar=foo