Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
788 views
Welcome To Ask or Share your Answers For Others

1 Answer

You'd want to use regex capture groups, as follows:

/v%(PATTERN.*
.*)@<!(PATTERN)%(.*
.*1)@!

Example

This might look scary, but it's actually quite simple:

  1. v is used to enable "very magic" regex (avoids the usage of backslashes for most special characters)
  2. PATTERN.* .* is PATTERN, followed by anything, a newline, and anything again
  3. (...)@<! is the pattern for negative look-behind: it means that we don't want what's between the braces to exist. So in our case, all of step 2 shouldn't exist
  4. (PATTERN) This is our actual word, this should exist! We capture it with braces for future usage
  5. .* .*1 is anything, a newline, anything again, and our captured group (see step 4)
  6. %(...)@! is a negative look-ahead, as before, we don't want what's between the braces to exist.

So basically, we want PATTERN, which is:

  • not preceded by a line containing PATTERN
  • not succeeded by a line containing PATTERN

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...