Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: How to capture this? (a nested group inside a repeated group)

Tags:

java

regex

How can I solve this Java regex problem?

Input:

some heading text... ["fds afsa","fwr23423","42df f","1a_4(211@#","3240acg!g"] some trailing text....

Problem: I would like to capture everything between the double quotes. (Example: fds afsa, fwr23423, etc.)

I have tried the following pattern:

\[(?:"([^"]+)",?)+\]

But when performing a Matcher.find(), it will result in a StackOverflowError, when using a larger input (but does work for a small input, this is a bug in Java). And even if it did work, then matcher.group(1) will only give "3240acg!g".

How can I solve this issue? (Or is the use of multiple patterns required, where the first pattern strips the brackets?)

like image 913
Devabc Avatar asked Nov 10 '11 13:11

Devabc


1 Answers

Get string between [ ] and then split by comma. It's much easier.

like image 62
Zernike Avatar answered Oct 21 '22 05:10

Zernike