Home  >  Article  >  Backend Development  >  javascript - 正则表达式如何匹配.$^等符号,假如字符串中包含这些有特殊含义的字符

javascript - 正则表达式如何匹配.$^等符号,假如字符串中包含这些有特殊含义的字符

WBOY
WBOYOriginal
2016-06-06 20:10:381252browse

如题
javascript - 正则表达式如何匹配.$^等符号,假如字符串中包含这些有特殊含义的字符

回复内容:

如题
javascript - 正则表达式如何匹配.$^等符号,假如字符串中包含这些有特殊含义的字符

用反斜杠转义不就可以了吗

如果要匹配的内容中包括元字符使用\进行转义。

假如 有字符串user$009 那么写成

user$099

就行了

<code>\.\$\^\*\?\[\]\+</code>

正则表达式中规定了一些具有特殊意义的字符即元字符,若要匹配这些元字符自身需要使用\进行转义。如果正则表达式的书写方式是构造函数形式,需要使用\\进行双重转义。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn