方括号内的交替运算符不起作用 [英] Alternation operator inside square brackets does not work

查看:96
本文介绍了方括号内的交替运算符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个javascript正则表达式来匹配搜索引擎字符串中的查询。我有一个交替的问题。我有以下的正则表达式:。

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}=

我希望能够匹配字符串'word'或'qw'除了'之外的字符串wd',但我尝试的一切都不成功。我想我可以做以下事情:

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}=

但它似乎不起作用。

推荐答案

替换 [WD |字| QW] (WD |字| QW)。

[] 表示字符sets,()表示逻辑分组。

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

这篇关于方括号内的交替运算符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆