-2

I want to search for a description string that has a keyword. Examples are the current output.

  description xxxx
  policy-group APPS
  description yyyy
  policy-group APPS
  description zzzz
  policy-group APPS_1

If I want to search only the description that has policy-group APPS, how do I do it? Notice that the policy group is coming on the second line after the description, and I think the first search will be missed. How can we prevent that?

Thanks

A solution and the most accessible reg expression.

2
  • 1
    welcome to SO. We invite you to share the effort made thus far, which regex are you currently using? I personally feel this question is borderline: if we focus on regex, it has a place here. If not, then it's more suitable for SuperUser Commented Jun 15 at 7:34
  • "Sometimes, you may find yourself frustrated by the comments. Maybe they make suggestions that you <s>have already tried</s> should already have tried. Maybe they totally misunderstand your problem." (see: stackoverflow.com/help/how-to-ask) this is, one of the reasons, you should share what your tried.
    – Luuk
    Commented Jun 15 at 7:49

1 Answer 1

1
  • Ctrl+F
  • Find what: ^description\h+\K.+?(?=policy-group APPS\b)
  • TICK Match case
  • TICK Wrap around
  • SELECT Regular expression
  • TICK . matches newline
  • Find All in Current Document

Explanation:

^                       # beginning of line
    description             # literally
    \h+                     # 1 or more horizontal spaces
    \K                      # forget all we have seen until this position
    .+?                     # 1 or more any character, not greedy
    (?=                     # positive lookahead, make sure we have after:
        policy-group APPS       # literally
        \b                      # word boundary
    )                       # end lookahead

Screenshot:

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.