Regular Expressions 101

Community Patterns

Replace regex with [does not contain string + contain string]

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(images\/.+)((?<!no-compress)\.png|\.jpeg|\.jpg|\.PNG|\.JPEG|\.JPG)
/
gm

Description

o let's imagine this here:

images/dwaudhawd_Test Picture.png

I would need to replace this into this:

images/dwaudhawd_Test Picture.webp

the thing you just have to pay attention is, to ignore all filenames that contains "no-compress".

so when this here comes:

images/dwaudhawd_Test Picture no-compress.png

it should not replace.

all possible image extensions:

.jpeg .jpg .png .JPEG .JPG .PNG

into

.webp

Submitted by Suman Maharjan - 2 years ago