admin管理员组文章数量:1429781
I'd like to pare 2 strings with each other, but I got a little problem with the Brackets. The String I want to seek looks like this:
CAPPL:LOCAL.L_hk[1].vorlauftemp_soll
Quoting those to bracket is seemingly useless.
I tried it with this code
var regex = new RegExp("CAPPL:LOCAL.L_hk\[1\].vorlauftemp_soll","gi");
var value = "CAPPL:LOCAL.L_hk[1].vorlauftemp_soll";
regex.test(value);
Somebody who can help me??
I'd like to pare 2 strings with each other, but I got a little problem with the Brackets. The String I want to seek looks like this:
CAPPL:LOCAL.L_hk[1].vorlauftemp_soll
Quoting those to bracket is seemingly useless.
I tried it with this code
var regex = new RegExp("CAPPL:LOCAL.L_hk\[1\].vorlauftemp_soll","gi");
var value = "CAPPL:LOCAL.L_hk[1].vorlauftemp_soll";
regex.test(value);
Somebody who can help me??
Share Improve this question edited May 16, 2011 at 9:44 Andreas asked May 16, 2011 at 9:35 AndreasAndreas 1937 bronze badges3 Answers
Reset to default 5It is useless because you're using string. You need to escape the backslashes as well:
var regex = new RegExp("CAPPL:LOCAL.L_hk\\[1\\].vorlauftemp_soll","gi");
Or use a regex literal:
var regex = /CAPPL:LOCAL.L_hk\[1\].vorlauftemp_soll/gi
Unknown escape characters are ignored in JavaScript, so "\["
results in the same string as "["
.
In value
, you have (1)
instead of [1]
. So if you expect the regular expression to match and it doesn't, it because of that.
Another problem is that you're using ""
in your expression. In order to write regular expression in JavaScript, use /.../g
instead of "..."
.
You may also want to escape the dot in your expression. .
means "any character that is not a line break". You, on the other hand, wants the dot to be matched literally: \.
.
You are generating a regular expression (in which [
is a special character that can be escaped with \
) using a string (in which \
is a special character).
var regex = /CAPPL:LOCAL.L_hk\[1\].vorlauftemp_soll/gi;
本文标签: javascriptBrackets in Regular ExpressionStack Overflow
版权声明:本文标题:javascript - Brackets in Regular Expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745550429a2662918.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论