Reputation: 11
(\$apple)(?!.\$apple)
\1\nFound
Given:
$apple hello
After running code, I expect:
$apple hello
found
But its not working, I am getting :
$apple
found hello
Upvotes: 0
Views: 66
Reputation: 91385
\$apple(?!.*\$apple).*?\R
$0Found
. matches newline
Explanation:
\$apple # literally $apple
(?!.*\$apple) # make we haven't $apple after
.*? # 0 or more any character, not greedy
\R # any kind of linebreak
Replacement:
$0 # the whole match, including linebreak
Found # literally
Screen capture (before):
Screen capture (after):
Upvotes: 1