如何对字符串中包含括号的字符串进行.match匹配? String1.match(“我怎么匹配这个(MATCH ME)”);JavaScript匹配字符串内的括号
没有一个答案让我得到我想要的。我可能只是做错了。我试图使我的问题基本,我认为这样做问我的问题是错误的。这是我特林修复声明:
$('[id$=txtEntry3]').focus(function() {
if (!DropdownList.toString().match($('[id$=txtEntry2]').val()) || $('[id$=txtEntry2]').val().length < 5) {
$('[id$=txtEntry2]').select();
ErrorMessageIn("The Ingredient number you entered is not valid.");
return;
}
ErrorMessageOut();
});
这工作正常我遇到的时候,它会匹配来自“txtEntry2”,有一个条目中的问题,它“()”。
那么它的有点坏,但它的工作原理为我需要做的。这是我做过什么来解决我的问题:
$('[id$=txtEntry3]').focus(function() {
if (!StripParentheses(DropdownList).match(StripParentheses($('[id$=txtEntry2]').val())) || $('[id$=txtEntry2]').val().length < 5) {
$('[id$=txtEntry2]').select();
if (!$('[id$=txtEntry2]').val() == "") {
ErrorMessageIn("The Ingredient number you entered is not valid.");
}
return;
}
ErrorMessageOut();
});
function StripParentheses(String){
x = String.toString().replace(/\(/g, '');
x = x.toString().replace(/\)/g, '');
return x;
}
使用\转义(和),像这样\\(和\\) – limc 2010-07-06 22:10:43