java - How to trim a string using regex? -
i have alphabet: {'faa','fa','af'} , have string: "faaf"
i have regex: "(faa|fa|af)*" helps me match string alphabet.
how make java trim string into: {fa,af}, correct way write string: "faaf" based on alphabet?
here code:
string regex = "(faa|fa|af)*"; string str = "faaf"; boolean ismatch = pattern.matches(regex, str); if(ismatch) { //trim string while(str.length()!=0) { pattern pattern = pattern.compile("^(faa|fa|af)(faa|fa|af)*$"); matcher mc = pattern.matcher(str); if (mc.find()) { string l =mc.group(1); alphabet.add(l); str = str.substring(l.length()); system.out.println("\n"+ l); } } }
thanks aaron helped me problem.
Comments
Post a Comment