0

I have some list:

$bad_words = ['aaa', 'bbb', 'ccc']
$good_words= ['__aaa', 'bbb==', '#ccc==']

By this lists I'd generate these rules:

$rules = ['/((?<!__)aaa)/', '/(bbb(?!==))/', '/((?<!#)ccc(?!==))/']

Problem: the ccc-rule is not correct (https://regex101.com/r/cC3hY7/1): it must to find strings like #ccc, #ccc-- or ccc== and exclude only strings like #ccc==

How to fix it?

Dmitry
  • 551
  • 6
  • 19

1 Answers1

1

You could simply use (*SKIP)(*F) like below.

    (?:#ccc==|bbb==|__aaa)(*SKIP)(*F)|(?:aaa|bbb|ccc)
#   |<- Strings you don't want ----->|<--strings you want-->

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274