I have a regex which searches for a newline symbol:
\r?\n|\r
And two examples:
#Example-1#
The correct answer is (B) 2 to 3. jfbgfdgdf sgdsgsd.
jfbgfdgdf sgdsgsd.
#End Example-1#
#Example-2#
The correct answer is (B) 2 to 3. jfbgfdgdf sgdsgsd.
jfbgfdgdf sgdsgsd.
#End Example-2#
Demo: https://regex101.com/r/zQ3nR3/1
I need to update a regex, so it finds only multiple instances of newline symbol, like these in Example-1 between text lines and not the one between text lines in Example-2
To match just the multiple linebreaks inside #Example text, use a limiting quantifier {2,} applied to (?:\r?\n|\r) and restrict it with a look-ahead:
(\r?\n|\r){2,}(?!#Example-\d)
See demo
The (?!#Example-\d) look-ahead returns a match only if there is no #Example-+digit after the multiple newline symbols.
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