Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternation operator inside square brackets does not work

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:

.*baidu.com.*[/?].*wd{1}=

I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:

.*baidu.com.*[/?].*[wd|word|qw]{1}=

but it does not seem to work.

like image 638
well actually Avatar asked Dec 21 '25 11:12

well actually


1 Answers

replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).

[] denotes character sets, () denotes logical groupings.

like image 155
bhamlin Avatar answered Dec 23 '25 23:12

bhamlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!