Skip to content

Instantly share code, notes, and snippets.

@nak3
Created November 29, 2014 14:17
Show Gist options
  • Save nak3/3b2b46bc9d88da17acc9 to your computer and use it in GitHub Desktop.
Save nak3/3b2b46bc9d88da17acc9 to your computer and use it in GitHub Desktop.
import java.util.regex.Pattern;
public class Matcher {
private static final Pattern SIMPLE_URL_PATTERN =
Pattern.compile("(\\w+://)|(git@)(.+@)*([\\w\\d\\.]+)(:[\\d]+){0,1}/*(.*)");
public static boolean isValid(String url) {
return SIMPLE_URL_PATTERN.matcher(url).matches();
}
public static void main(String[] args) {
if (isValid(args[0])) {
System.out.println("PASS: matched");
} else {
System.out.println("FAIL: not mached");
}
}
}
@nak3
Copy link
Author

nak3 commented Nov 29, 2014

Compile

javac Matcher.java

Test

java Matcher git@example.com:openshift/xxx.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment