Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change regular expression

I have the following configuration which use a regular expression, basically it says process all files excluding ComponentA.

I would need to change the property regex so it can can exclude additionally ComponentB.

How to change the regex?

   {
       regex: /^((?!.*?ComponentA).)*$/
    }
like image 592
Radex Avatar asked Feb 23 '26 22:02

Radex


1 Answers

Your current regex:

/^((?!.*?ComponentA).)*$/

asserts that ComponentA is not present ahead before matching each character. In other words it performs this assertion for each character hence it will perform very slow for bigger strings.

It is better to change this to one time assertion like this:

/^(?!.*ComponentA).*$/

Since you want to disallow ComponentB also so just use an alternation in negative lookahead expression:

/^(?!.*(?:ComponentA|ComponentB)).+$/
like image 179
anubhava Avatar answered Feb 26 '26 10:02

anubhava