how can i extract bold range string in below
string :
- hello world blah -d blah vlaah -n blah vlahh
- hello world blah -n blah vlahh -d blah vlaah
- hello world blah -d blaaah
I tried. -[dn] .*$ but it found longest match string like below
- hello world blah -d blah vlaah -n blah vlahh
I want to extract shortest match string . thanks in advance
You can use a negative lookahead to avoid matching another -d/-n in the match:
-[dn] (?!.*?-[dn]).*$
RegEx Demo
Could throw a greedy .* before to eat up:
^.*(-[dn] .*)$
And grab matches of the first capture group. See test at regex101
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With