regex - Java how to use pattern matcher using regular expressions to find certain string -
i not familiar patterns & matchers, , pretty stuck problem.
i have string manipulate in java. understand have use
pattern p = pattern.compile("\\[(.*?)\\]"); matcher m = p.matcher(in); while(m.find()) { string found = m.group(1).tostring(); } but in string, let's have following examples:
string in = "test goes here [a#1234|567]"; //or string in = "test goes here [b#1234|567]"; //or string in = "test goes here [c#1234|567]"; i want find [a# | ] or [b# | ] or [c# | ] in string, how use regex find expression?
use [abc]# in regex match expression.
pattern p = pattern.compile("(\\[[abc]#.*?\\])"); if fields digit can safely use \d+
pattern p = pattern.compile("(\\[[abc]#\\d+\\|\\d+\\])");
Comments
Post a Comment