开发者

vbscript multiple replace regex

开发者 https://www.devze.com 2022-12-31 19:59 出处:网络
How do you match more than one pattern in vbscript? Set regEx = New RegExp reg开发者_Python百科Ex.Pattern = \"[?&]cat=[\\w-]+\" & \"[?&]subcat=[\\w-]+\" // tried this

How do you match more than one pattern in vbscript?

Set regEx = New RegExp

reg开发者_Python百科Ex.Pattern = "[?&]cat=[\w-]+" & "[?&]subcat=[\w-]+" // tried this
regEx.Pattern = "([?&]cat=[\w-]+)([?&]subcat=[\w-]+)" // and this

param = regEx.Replace(param, "")

I want to replace any parameter called cat or subcat in a string called param with nothing.

For instance

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

I would want to remove cat=meow and subcat=purr from each string.


regEx.Pattern = "([?&])(cat|dog)=[\w-]+"

param = regEx.Replace(param, "$1") ' The $1 brings our ? or & back


Generally, OR in regex is a pipe:

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

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

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

Another option is to use or on the not-shared parts:

[?&](cat|dog|bird)=[\w-]+
0

精彩评论

暂无评论...
验证码 换一张
取 消