正则表达式仅适用于字符a-z,A-Z [英] Regular expression for only characters a-z, A-Z
问题描述
我不知道如何在JavaScript或jQuery中创建正则表达式。
I don't know how to create a regular expression in JavaScript or jQuery.
我想创建一个正则表达式来检查字符串是否只包含字符在az和AZ之间进行任何安排。
I want to create a regular expression that will check if a string contains only characters between a-z and A-Z with any arrangement.
编辑
当我尝试制作正则表达式
When I tried to make regex
/^[a-zA-Z\s]+$/
也接受空格。它不起作用。可能是什么错误?
to accept white spaces as well. It is not working. What could be the mistake?
我正在 JavaScript RegExp示例:在线正则表达式测试器 。
推荐答案
/^[a-zA-Z]*$/
如果您不想允许空匹配,请将 *
更改为 +
。
Change the *
to +
if you don't want to allow empty matches.
字符类( [...]
),锚点( ^
和 $
),重复( +
, *
)
Character classes ([...]
), Anchors (^
and $
), Repetition (+
, *
)
/
只是分隔符,它表示正则表达式的开头和结尾。现在,您可以使用修饰符。
The /
are just delimiters, it denotes the start and the end of the regex. One use of this is now you can use modifiers on it.
这篇关于正则表达式仅适用于字符a-z,A-Z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!