1

如何使用 VS Find/Replace 进行替换:

: $('a[name="lnkFind"]').on('click', 函数

用这个: $(document).on("click", "a[name='lnkFind']", function

我不确定哪些字符需要转义 - 单引号或双引号或两者兼而有之?我尝试过的所有模式似乎都找不到匹配项。

4

3 回答 3

2

您需要转义许多这些字符。

Find/Replace 会抱怨未转义的(and ),甚至是最后的裸露(,因为它缺少匹配的). 还有方括号,用于字符集,最后是$.

所以这应该作为模式工作:

\$\('a\[name="lnkFind"\]'\).on\('click', function
于 2012-08-22T17:23:33.063 回答
1

Except in special cases (such as vim regex), in general you can escape any and all special characters in regex to get their literal form, i.e. escaping a special character that doesn't need to be escaped, won't do any harm.

That said, here's the minimum that needs to be escaped:

\$\('a\[name="lnkFind"]')\.on\('click', function

I don't think you'll need to escape anything in the replacement, because only a $ or \ followed by a number will be interpreted.

于 2012-08-22T17:59:54.740 回答
1

您应该查看正则表达式中的特殊字符列表。

$, ., [,]都应该被转义。

http://www.fon.hum.uva.nl/praat/manual/Regular_expressions_1__Special_characters.html

于 2012-08-22T16:54:23.643 回答