Exclude a word from Regex using PHP and YITH Bulk Editing

73 Views Asked by At

I'm New to PHP and Regex, I'm trying to exclude a word from the search using Yith Bulk Editing Woocommerce and WordPress.

Now I paid for the plugin but the support is very slow and not helpful at all.

When I use the regular expression to look for products I have over 10,000 of them.

An example I have Fasteners Hex Nuts over 3500 of them I would like to exclude any hex nut that has nylon in it the title. so I used the following in the search Hex Nut.?+(?!Nylon).?+$ but that gives me no products found, I have come across a website https://regex101.com/ that helps you debug your regex but for someone that is now to it it does not work.

I have tried the following

Hex Nut.?+(?!Nylon) - No Results

Hex Nut.?+(?:Nylon) - No Results

Hex Nut.?+(?:Nylon) - No Results

Hex Nut^/(?!Nylon)  - No Results

Platforms are the following

YITH WooCommerce Bulk Product Editing - Version 1.2.29

Woocommerce - Version 4.9.0

WordPress - Version 5.6

1

There are 1 best solutions below

0
On

The Answer is ^Hex Nut(?!.*\bNylon\b).*$ see https://regex101.com/r/0H1Tig/1

I needed to use a word boundary to make it work, as far as I can tell is the same as double quotations.

\b Matches, without consuming any characters, immediately between a character matched by \w and a character not matched by \w (in either order). It cannot be used to separate non words from words.