1

I am running this in MariaDB 10.0.26 on PCRE 8.39.

Say, i want to exclude Printer,Cartridge,Toner Sets,Kits, or Bundles.

So I wrote this:

(?<items>Printer|Cartridge|Toner)(?<sets>Kit|Bundle|Set)(?(?=\g<items>)(?!\g<sets>))

The named groups shouldn't much matter, i was just trying everything.

Simply saying, I want this expression:

titleField regexp '(?<items>Printer|Cartridge|Toner)(?<sets>Kit|Bundle|Set)(?(?=\g<items>)(?!\g<sets>))' to return 0 and not 1.

I am at this point lost what i am doing wrong, even though this must be something FACEPALM(!~~!) worthy. Please help.

  • Looks like you are looking for a negative lookbehind, butsince Iit cannot be of unknown width in pcre use a lookahead `^(?!.*(Printer|Cartridge|Toner).*(Kit|Bundle|Set)).*(Kit|Bundle|Set)` – Wiktor Stribiżew Aug 02 '16 at 05:56
  • Wiktor, please post a reply so that i can accept it as correct. ^(?!.*(Printer|Cartridge|Toner).*(Kit|Bundle|Set)) You obviously copied in the second part twice. Thanks for the help, that worked. – Menashe Borbely Aug 02 '16 at 17:13

1 Answers1

1

You may use

^(?!.*(Printer|Cartridge|Toner).*(Kit|Bundle|Set)) 

The lookahead (?!.*(Printer|Cartridge|Toner).*(Kit|Bundle|Set)) will fail the match if a string contains Printer, Cartridge or Toner ((Printer|Cartridge|Toner)) somewhere after 0+ chars other than a newline (.*).

You can test the regex here.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563