Skip to content

Commit

Permalink
regex
Browse files Browse the repository at this point in the history
  • Loading branch information
joshHug committed Mar 25, 2017
1 parent 5b70cdb commit b58628b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions regex/RegexDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegexDemo {
public static void simpleDemo() {
String s1 = "moons";
String s2 = "XxmoonsxX";
String regexString = "m[aeiou]{2}ns";
System.out.println(s1.matches(regexString));
System.out.println(s2.matches(regexString));
}

public static void matcherDemo() {
String seq = "GPCGGWCAASCGGPYACGGWAGYHAGWHWAH";
String regexString = "C.{2,4}C.{3}[LIVMFYWCX].{8}H.{3,5}H";
Pattern pat = Pattern.compile(regexString);

Matcher mat = pat.matcher(seq);
while (mat.find()) {
System.out.println("Match: " + mat.group(0));
}
}

public static void groupDemo() {
String seq = "jim,cs61b-abe,30117827,xi,cs61b-bqd,15039872";
String regexString = "(cs61b-[a-z]{3}),([0-9]+)";
Pattern pat = Pattern.compile(regexString);
Matcher mat = pat.matcher(seq);
while (mat.find()) {
System.out.println("entire match: " + mat.group(0));
System.out.println("login: " + mat.group(1) + ", sid: "
+ mat.group(2));
}
}

public static void main(String[] args) {
//simpleDemo();
//matcherDemo();
//groupDemo();
}
}

0 comments on commit b58628b

Please sign in to comment.