Capture multiple subgroups of a repeating group

Mostly I want to capture several subgroups. I'm not a repeat group capture and capture a repeating group

If there is aaa , I want to get the following subgroups:
$ 1: a $ 2: a $ 3: a

This can be achieved using (a) (a) (a) .

Now I'm trying to do it as something like strings (a) {3} , unfortunately, only leads to $ 1: a

EDIT: I am trying to do this in Java. I already have another solution that uses StringBuilder to generate the correct template, repeating the capture group for the number of expected events.
This question was more out of curiosity and because I was looking for an easier way to do this.

What Some1.Kill.The.DJ mentioned is what I tried to do in Java.

+1
source share
1 answer

For the correct answer to this question, the actual use case and the mechanism of regular expressions will be required, but for the example that you provided, this can be done using the global template matching with the expression (a). In python, this will be done like this:

>>> import re
>>> test = "aaa"
>>> re.findall(r'(a)', test)
['a', 'a', 'a']

Perl /g .. .

0

All Articles