[英]Simple JavaScript Regex that contains both square brackets
I'm trying to write a Regex of the form: najfo359f+-q3f#~[+0asa123123]a'/.df;ekfm345我正在尝试编写以下形式的正则表达式:najfo359f+-q3f#~[+0asa123123]a'/.df;ekfm345
This is what I have so far:这是我到目前为止所拥有的:
/.*[.*0*/d+].*/
But I can't match the simple [2245]
and when I try to escape \
the opening square bracket my code doesn't execute.但是我无法匹配简单的
[2245]
并且当我尝试转义\
左方括号时,我的代码不会执行。
What am I missing?我错过了什么?
A few observations:几点观察:
0
in the middle of your regex seems a bit arbitrary and doesn't appear to be considered in any of your criteria.0
似乎有点随意,并且在您的任何标准中似乎都没有考虑。/d
, maybe you meant \d
?/d
,也许您的意思是\d
? A backslash \
is used to indicate escape sequences.\
用于指示转义序列。 You're looking for something more akin to:您正在寻找更类似于:
/.*\[.*\d+\].*/
In context with Javascript:在 Javascript 的上下文中:
const pattern = /.*\[.*\d+\].*/; console.log(pattern.test("najfo359f+-q3f#~[+0asa123123]a'/.df;ekfm345")); console.log(pattern.test("[2245]"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.