I want to Select specific text between two strings using regex.
e.g:
foo I have four toys bar //single line
foo //multiline
I
have
four
toys
bar
foo I have three pets bar
foo
I
have
three
pets bar
How to select text between "foo" and "bar" with specific word containing "four"
Output:
I have four toys
I
have
four
toys
My code:
foo[\s\S]*?(four)[\s\S]*?bar
My code is working fine but problem is that when when "four" word does not comes between "foo" and "bar" it is selecting all text till "four" word
foo I have three pets bar
foo I have four toys bar
foo
I
have
three
pets bar
I just want text between "foo" and "bar" when it is containg specific word "four"