Reputation: 133
I want to find repeating patterns in the following sentence using reqular expressions in java:
username|s:5:"derick256";privilege|s:5:"derick542";premium|s:5:"derik542";
I need to extract the following, and potentially more, so I need a solution that is easily expandable...
derick256
derick 542
derik542
This is my code...
String re1="((?:[a-z][a-z0-9_]*))"; // Variable Name 1
String re2=".*?"; // Non-greedy match on filler
String re3="(?:[a-z][a-z0-9_]*)"; // Uninteresting: var
String re4=".*?"; // Non-greedy match on filler
String re5="((?:[a-z][a-z0-9_]*))"; // Variable Name 2
Pattern p = Pattern.compile(re1+re2+re3+re4+re5,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(strLine);
if (m.find()){
String word1=m.group(1);
String word2=m.group(2);
System.out.print("("+word1.toString()+")"+"("+word2.toString()+")"+"\n");
}
But I only got username derick256
. Could anyone please assist me to understand the error.
Upvotes: 3
Views: 835