javascript Javascript正则表达式单引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14378998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript regular expression single quotes
提问by Mosh Feu
My Regex is:
我的正则表达式是:
var re = /^[a-z A-Z._]{1,15}$/;
I want to allow this: '
(Single Quote).
我想允许:('
单引号)。
How can I do this?
我怎样才能做到这一点?
回答by Rinku
You can use the following regex for example to allow a string like abcd'dfgh
:
例如,您可以使用以下正则表达式来允许像这样的字符串abcd'dfgh
:
/^[A-Za-z\/\']+[A-Za-z]$/
回答by Naveed S
To allow single quote, add it in the character class like ^[a-z A-Z._']{1,15}$
要允许单引号,请将其添加到字符类中,例如 ^[a-z A-Z._']{1,15}$
This regex allows '
matching 'abc'_
, a'b'c_
etc.
此正则表达式可以'
匹配'abc'_
,a'b'c_
等等。