0

I have a regex with a character sequence. I want the sequences parts into groups.

Pattern e_1394Pattern = Pattern
        .compile("\\dR\\|\\d\\|(((([^\\|]))*\\|){11})");

String resultLine = "\4R|1|^^^02^Myo^1021406330|25.6^F|ng/mL||N||F||Administrator||20140318215839|";

This pattern works fine, but I need the groups of the following Part (((([^\\|]))*\\|){11}). Is this possible using a short regex?

This is no option: \\dR\\|\\d\\|((([^\\|]))*\\|) ((([^\\|]))*\\|) ((([^\\|]))*\\|) ((([^\\|]))*\\|)....

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
S.F
  • 1
  • possible duplicate of [Java regex: Repeating capturing groups](http://stackoverflow.com/questions/6939526/java-regex-repeating-capturing-groups) – Joe Aug 28 '14 at 13:22
  • sorry, I think that is not the same... I want the repeated part of the regex '(ab){n}' in groups. the result of this is one group 'ab' – S.F Aug 28 '14 at 13:50

1 Answers1

0

Not sure I understand your need, but how about:

You can repeat pattern with (?1) or \g1 that will repeat the pattern used for group 1, depending on regex flavor.

In your case:

"\\dR\\|\\d\\|(((([^\\|]))*\\|){11})"

is the same as (removing superfluous grouping):

"\\dR\\|\\d\\|([^\\|]*\\|)(?1)(?1)(?1)(?1)(?1)(?1)(?1)(?1)(?1)(?1)"
Toto
  • 89,455
  • 62
  • 89
  • 125