user3826343
user3826343

Reputation: 21

Find a repeating pattern which has a repeating pattern

I get a very large string that contains n number of records. Each record consists of 3 groups of text, the first 3 of which are encased in angle brackets. Each group of text is 1-n characters in length. This overall pattern repeats 1-n times within the string. (see example below).

<text1a><text2a><text3a>text4a<text1b><text2b><text3b>text4b<text1c><text2c><text3c>text4c
|--------single record-------||-------single record--------||-------single record--------|

Using the above as the input string, I'm trying to develop a pattern matcher that would return to me each individual record in the string. I've tried many variations but either get nothing, only the first record, or the whole string. I've read many posts regarding repeating patterns and have tried to apply the principles with little success. I been successful at finding IP addresses, phone numbers, and other patterns that might repeat within a given string, but this pattern eludes me. Thanks in advance.

Upvotes: 0

Views: 134

Answers (1)

user3826343
user3826343

Reputation: 21

I am implementing this in Java. The solution I found is the following pattern...

 String patternString = "(\\[.*?\\]){3}([^\\[])*";
 Pattern pattern = Pattern.compile(patternString);

This pattern will match a record (substring of larger string) consisting of 3 bracketed sections containing any number of characters followed by any number of characters except for a bracket (indicating a new record)

Thanks for the help.

Upvotes: 1

Related Questions