0

Given that I have following text;

123            XXXXX                                         123-456-678
               YYYYYY
               121-121-1121-11 Foo
               Street 11

               12121 FINLAND
               Building
               Lorem Ipsun
               Ipsum


124            XXXXX                                         123-456-890
               YYYYYY
               121-121-1121-21 Bar
               Street 12

               12121 SWEDEN
               House
               Lorem Ipsun2
               Ipsum2

How would I capture this into two matches? Meaning first one would start with 123 line and including all the lines until we encounter 124 line, which would be another match.

Most success I've had with (?:^\d+)(\s+.*)+ but thats way too greedy.

2 Answers 2

2

You can use this regex:

/^(\d+.*?)(?=^\d+|\z)/gms

RegEx Demo

1
  • Really nice and simple. Works beautifully!
    – kakoni
    Commented Oct 3, 2014 at 11:20
1

You could try this regex also,

(?<=\n|^)((?:\d+.*?\n)(?=\d+)|(?:\d+.*?)(?=$))

DEMO

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.