0

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.

HamZa
  • 14,671
  • 11
  • 54
  • 75
  • 3
    Well, show us what you've got so far? That would probably help you out wouldn't it? – Bono Dec 19 '14 at 19:08
  • THe pattern should look like [this](https://regex101.com/r/dA6wZ5/1). I've added some explanation. I think you don't know how to use it in java. Which means you might look at [this question](http://stackoverflow.com/questions/6020384/create-array-of-regex-matches) – HamZa Dec 19 '14 at 19:14
  • What does `repeating pattern` have to do with it? Is it a pseudo-record separator? What should happen if there is discontinuity? –  Dec 19 '14 at 20:52

1 Answers1

1

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.