Javascript JQuery正则表达式接受字母数字字符和'-

Javascript JQuery正则表达式接受字母数字字符和'-,javascript,regex,Javascript,Regex,我试图弄清楚如何让正则表达式接受某些特殊字符:、、、和-以及字母数字字符。我试过了,但没用,而且我对regex很陌生,有人能帮我吗 这是我的尝试,令人惊讶的是,没有成功 /^\d+/,\'\-\$/i 像这样的 /[0-9a-zA-Z',-]+/ 如果必须是完整字符串,可以使用 /^[0-9a-zA-Z',-]+$/ 试一试 (假设您指的是ASCII字母、数字和下划线,即“字母数字”)。\d是[0-9]的缩写,它不是任何字母数字字符 /^[\w,'-]+$/i 我们应该做到这一点 这句话

我试图弄清楚如何让正则表达式接受某些特殊字符:
-
以及字母数字字符。我试过了,但没用,而且我对regex很陌生,有人能帮我吗

这是我的尝试,令人惊讶的是,没有成功

/^\d+/,\'\-\$/i
像这样的

/[0-9a-zA-Z',-]+/
如果必须是完整字符串,可以使用

/^[0-9a-zA-Z',-]+$/
试一试


(假设您指的是ASCII字母、数字和下划线,即“字母数字”)。

\d
[0-9]
的缩写,它不是任何字母数字字符

/^[\w,'-]+$/i
我们应该做到这一点

这句话的意思是:

^ - match the start of the line
[ - match any of the following characters (group #1)
    \w - any word (meaning differs depending on locale;
         generally, any letter, number or the `-` character.)
    ,  - a comma
    '  - an apostrophe
    -  - a dash
] - end group #1
+ - one or more times
$ - match the end of the line
/i - set case-insensitivity.

这只是JavaScript,不是jQuery。(事实上,在某种程度上,它可以被理解为语言不可知论。)实际上,
\w
意味着
\d
——请参见:)
^ - match the start of the line
[ - match any of the following characters (group #1)
    \w - any word (meaning differs depending on locale;
         generally, any letter, number or the `-` character.)
    ,  - a comma
    '  - an apostrophe
    -  - a dash
] - end group #1
+ - one or more times
$ - match the end of the line
/i - set case-insensitivity.