Reputation: 157
I need get all text between Lorem
until the last occurrence of CEP
code.
I'm just getting the first occurrence, but some paragraphs have two CEP
codes.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
proident, sunt in culpa qui officia deserunt CEP 142802/AA, mollit anim id est laborum CEP 13342802/AA.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
proident, sunt in culpa qui officia deserunt CEP 11123/AA
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
proident, sunt in culpa qui officia deserunt CEP 2223/AA
Se example working here: https://regex101.com/r/eZ0yP4/2
Thanks!
Upvotes: 1
Views: 140
Reputation: 174696
Use positive lookahead assertion like below.
(?s)Lorem.*?CEP \d+\/[A-B]{2}(?=\.?(?:\n\n|$))
OR
(?s)Lorem(?:(?!\n\n).)*CEP \d+\/[A-B]{2}
(?:(?!\n\n).)*
matches any character but not of \n\n
zero or more times. \n\n
represents a blank line. (?s)
DOTALL modifier which makes dot in your regex to match even line breaks.
Upvotes: 2
Reputation: 67968
Lorem.*CEP \d+\/[AB]{2}
Try this.See demo.
https://regex101.com/r/eZ0yP4/3
Upvotes: 0