Skip to content

Instantly share code, notes, and snippets.

@jonasbits
Created October 11, 2017 22:48
Show Gist options
  • Save jonasbits/782ab527e71bb67bd83a3b4d627e3e79 to your computer and use it in GitHub Desktop.
Save jonasbits/782ab527e71bb67bd83a3b4d627e3e79 to your computer and use it in GitHub Desktop.
Inverse regex to match non .bit urls
//compile with 'javac RegexTest.java'
//run with java RegexTest example.com
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static void main(String[] args) {
//line bellow does not work, must include regex inline instead
// String regex = "((\\S+)\\s*some\\s*";
Pattern pattern = Pattern.compile("(?!([^\\/])+\\.bit[\\/\\s]?.*).*");
for (int i = 0; i < args.length; ++i) {
Matcher matcher = pattern.matcher(args[i]);
System.out.println("'" + args[i] + "' does " + (matcher.matches() ? "" : "not ") + "match '" + "inlineRegEx as non .bit url" +"'");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment