java - Regex with two patterns -
i have requirement in want 2 different items form 1 long string. have got below program in required items when group(1) , group(6). want in group(1) , group(2).
import java.util.regex.matcher; import java.util.regex.pattern; public class regexexample { public static void main(string args[]) { string somepattern = "((123|456)-(0|1)-((\\d-?){8})-\\d{1})/(\\d{2})"; string str = "/somethingwaste/123-0-1234-5678-9/10"; matcher p = pattern.compile(somepattern).matcher(str); while (p.find()) { system.out.println(p.group(1)); system.out.println(p.group(6)); }
any pointers directions appriciated.
thanks
this should it
string somepattern = "((?:123|456)-[01]-(?:\\d-?){8}-\\d)/(\\d{2})";
the ?:
makes ()
non-capturing.
Comments
Post a Comment