user3919298
user3919298

Reputation: 3

Regex match everything from the last occurrence of key to another key

I have this text:

OLD >> AAAAAA AA-BB dssd sdg Ad sdg ds Adsd gs AAA sdg dsg GGGGGG GG sdgds AAAA GF-S sdg . sdg. - 4353 ds gsd sdg GDS GDG 343 33 sdgsg sdgs DGSAGG DSDG S DG

new text

AAAAAA AA-BB dssd sdg Ad sdg ds Adsd gs AAA sdg dsg GGGGGG GG sdgds AAAA GF-S sdg . Asdg. AA sdg dsg - 4353 ds gsd sdg GDS GDG 343 33 sdgsg sdgs DGSAGG DSDG S DG And I want to extract the last occurrence of an uppercase string like ([A-Z -]+){5,100} before a number: 4353

So in this case the results should be:

AAAA GF-S

I tried /([A-Z -.]+){5,100} (.+) 4353/i but it gets me the first.

Thanks for the fast answers, I made a modification in the search text. It should be last expresion that has only upper cases and it length bigger than 5

Upvotes: 0

Views: 69

Answers (2)

revo
revo

Reputation: 48751

Updated

Try this:

.*(\b[A-Z][A-Z -.]{5,100})(?=.*4353)\K

Live demo

Upvotes: 1

anubhava
anubhava

Reputation: 786091

You can use this regex:

([A-Z][A-Z .-]{5,100})(?= [a-z .-]*4353)

RegEx Demo

Upvotes: 1

Related Questions