regex - How to crop multiple text from String in Java? -
i want crop portion of string:
" test [abc:123456] sting multiple properties [abc:98765] ..."
so in result want crop string between "[ ]". {here abc:12345 , abc:98765} note there can n number of property. best way result.
public static void main(string[] args) { string input = "test bla [abc56465:asd] asdasdqwd [def:345]"; pattern pattern = pattern.compile("\\[(.*?)\\]"); matcher match = pattern.matcher(input); while(match.find()){ system.out.println(match.group()); } }
follow tutorials niels. solution. output without "[ ]" replace:
system.out.println(match.group());
with:
system.out.println(match.group(1));
as mentioned in comments.
Comments
Post a Comment