Created
January 25, 2018 15:45
-
-
Save hinerm/5aad1098b0aa15be4c749b098354bd12 to your computer and use it in GitHub Desktop.
Regex fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.StringJoiner; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class Sandbox { | |
static String CHANGE_PATTERN = "ins|del|dup|>"; | |
static String NUC_PATTERN; | |
// static initializer | |
{ | |
StringJoiner sj = new StringJoiner("|", "(", ")(?:hello)"); | |
for (Change change : Change.values()) { | |
sj.add(change.toString()); | |
} | |
CHANGE_PATTERN = sj.toString(); | |
} | |
public static void main(String... strings) throws InterruptedException { | |
new Sandbox(); | |
// Pattern p = Pattern.compile(regex); | |
Pattern p = Pattern.compile("(?i)" + CHANGE_PATTERN); | |
Matcher matcher = p.matcher("C.153A>helloC, C.-1delhello"); | |
System.out.println(matcher.groupCount()); | |
while (matcher.find()) { | |
System.out.println(matcher.group(0)); | |
System.out.println(matcher.group(1)); | |
Change parsedChange = Change.nameValue(matcher.group(1)); | |
} | |
// System.out.println(matcher.matches()); | |
// System.out.println(matcher.group()); | |
// while (matcher.find()) { | |
// matcher. | |
// } | |
// System.out.println(CHANGE_PATTERN.toString()); | |
} | |
enum Change { | |
INS("ins"), DEL("del"), DUP("dup"), SUB(">"), RENAME("??"); | |
private String name; | |
private Change(String s) { | |
name = s; | |
} | |
@Override | |
public String toString() { | |
return name; | |
} | |
public static Change nameValue(String input) { | |
for (Change change : Change.values()) { | |
if (change.name().equalsIgnoreCase(input)) { | |
return change; | |
} | |
} | |
return valueOf(input); | |
} | |
enum Nucleotdes { | |
G, C, A, T; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment