Vbscript multiple replace regex

How do you map multiple patterns in vbscript?

Set regEx = New RegExp regEx.Pattern = "[?&]cat=[\w-]+" & "[?&]subcat=[\w-]+" // tried this regEx.Pattern = "([?&]cat=[\w-]+)([?&]subcat=[\w-]+)" // and this param = regEx.Replace(param, "") 

I want to replace any cat or subcat parameter in a string named param without anything.

for instance

 string?cat=meow&subcat=purr or string?cat=meow&dog=bark&subcat=purr 

I would like to remove cat = meow and subcat = purr from each line.

+4
source share
2 answers

Typically, OR in regex is a pipe:

 [?&]cat=[\w-]+|[?&]subcat=[\w-]+ 

In this case, this will also work: make sub optional:

 [?&](sub)?cat=[\w-]+ 

Another option is to use either in non-shared parts:

 [?&](cat|dog|bird)=[\w-]+ 
+2
source
 regEx.Pattern = "([?&])(cat|dog)=[\w-]+" param = regEx.Replace(param, "$1") ' The $1 brings our ? or & back 
+3
source

Source: https://habr.com/ru/post/1310548/


All Articles