0

I'm trying to highlight the text within a parenthesis ONLY if it contains the words "RSVP" and a section symbol "§".

So far I have this but I can't make it to work: \([^\]()*(?:USCS|§)[^\]()*)

My goal is to target BOTH the parenthesis and the text inside.. for example:

(dog) (cat) (RSVP random text)

It should only highlight (dog) and (RSVP random text), and ignore cat.

regex demo

Thank you in advance!

ixcode
  • 611
  • 8
  • 17
  • 1
    `\([^()]*(?:RSVP|§)[^()]*\)`. `(dog)` won't match, it has neither `§` nor `RSVP`. – Wiktor Stribiżew Apr 07 '22 at 14:47
  • Aww thank you again! Sorry I couldn't make it work on my own try.. – ixcode Apr 07 '22 at 14:49
  • 1
    It is just the same, just you need `(` and `)`, all escaped outside square brackets and non-escaped inside brackets. – Wiktor Stribiżew Apr 07 '22 at 14:49
  • @WiktorStribiżew Can you please tell me how can I target all of this `(RSVP 1111())`? Is there a way to set this kind exception? It can have multiple nested parenthesis inside such as `(RSVP (a)(b)(1))`. – ixcode Apr 07 '22 at 15:00
  • 2
    No if you need any nesting level support. Besides, it will be difficult to decide where `RSVP` must be checked, on the first nested level or in all of them. Better [extract all substrings between nested parentheses](https://stackoverflow.com/questions/546433/regular-expression-to-match-balanced-parentheses) and then check if they contain the necessary text. – Wiktor Stribiżew Apr 07 '22 at 15:01
  • @WiktorStribiżew How about if it's always in the first level, is that possible? Anyway, thanks very much for your help, really appreciate it! – ixcode Apr 07 '22 at 15:06
  • 1
    Maybe like [this](https://regex101.com/r/FvLHWM/1). – Wiktor Stribiżew Apr 07 '22 at 19:22
  • @WiktorStribiżew Aww you're a legend sir! Thank you very much! ^_^ – ixcode Apr 07 '22 at 19:37

0 Answers0