Skip to content

Instantly share code, notes, and snippets.

@agtokty
Last active February 12, 2022 12:40
Show Gist options
  • Save agtokty/c9b1f6bc9fb56bd022f2819ee0e8dcf9 to your computer and use it in GitHub Desktop.
Save agtokty/c9b1f6bc9fb56bd022f2819ee0e8dcf9 to your computer and use it in GitHub Desktop.
public class RegexText {
public static void main(String[] args) {
final String[] testStrings = {
"v2/rt.do.reg1/t", // Match
"v2/a1.b2.c2/t", // Match
"v2/a1;b2;c2/t", // Match
"v2/a1-b2-c2/t", // Match
"v3/rt.do.reg1/t", // Not Match
"v2/rt.do.reg1/t2", // Not Match
"v2/rt.do.reg1/t/" // Not Match
};
final String regex = "^v2\\/(.*)\\/t$";
final Pattern pattern = Pattern.compile(regex);
for (String input : testStrings) {
Matcher matcher = pattern.matcher(input);
if (matcher.matches()) {
System.out.println("Match: " + input);
} else {
System.out.println("Not Match: " + input);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment