How can I match a string literal then reverse direction then match another string literal above it?
Basically match "match" then look behind and match "here:" then match from "here:" to end of string (to eventually delete)
-- input --
Keep this
here:
match test test
this should be deleted
-- expected output (after match and delete) --
Keep this
You don't need to make this movement, you only need to find "here:" and to ensure that the string contains "match" after (if it is not the case, the pattern will fail):
(?s)here:.*?match.*
(?s)
the dot can match newlines
However, if it is possible, you will probably obtain better performances using indexOf
method with "match" and "here:", comparing the result and cuting the string at the index of "here:"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.