Reputation: 3093
I have the following string
someaddres.com/?f=[B]a-test,a test,Test[C]test a,test2
I'm trying to pull two groups from it:
[B]a-test,a test,Test
and
[C]test a,test2
How would I repeat the capture group until a character not present in the group is found?
My current regex is: f=(\[[A-Z]\][a-zA-Z0-9,-\s]+)
Upvotes: 2
Views: 1140
Reputation: 785088
You may use this regex with a captured group that will match twice:
(\[\w+\][^[]+)
If you want 2 capture groups in single match then use:
(\[\w+\][^[]+)(\[\w+\][^[]+)
RegEx Details:
(
: Start capture group #1
\[
: Match a [
\w+
: Match 1+ word characters\]
: Match a ]
: Match 1+ of any characters that is not
[`)
: End capture group #1Upvotes: 1