I was experimenting with regex and got stuck with the following problem.
Say, I have lines which start and end with batman
and some arbitary number in between and i want the numbers in capture group as well as the words batman
.
batman 12345 batman
batman 234 batman
batman 35655 batman
batman 1311 batman
This is easy to achieve (simple one => (\s*batman (\d+) batman\s*)
DEMO).
Now I tried a little bit more.. putting the same data in a capture tag (#capture)
#capture
batman 12345 batman
batman 234 batman
batman 35655 batman
batman 1311 batman
#capture
#others
batman 12345 batman
batman 234 batman
batman 35655 batman
batman 1311 batman
#others
I am trying to capture lines only between #capture
and i tried
(?:#capture)(\s*batman (\d+) batman\s*)*(?:#capture)
which matches the pattern but includes only last iteration in capture group i.e $1=>batman $2=>1311 $1=>batman
DEMO
I also tried to capture the repeating group using
(?:#capture)((\s*batman (\d+) batman\s*)*)(?:#capture)
This one captures everything.. but in different groups.. DEMO
Can someone help me understanding and solving this problem?
Expected results: capture only the group in #capture
and all numbers in a group so that replacement could be easy.
Thanks.