RegEx that doesnt allow tilde / console key

后端 未结 1 818
情书的邮戳
情书的邮戳 2021-01-21 17:43

I have the following regex

(^[a-zA-z]+([a-zA-Z\\s-]*)[a-zA-z]+$)

It disallow all special chars except ( ` ) the console key. Could someone expl

相关标签:
1条回答
  • 2021-01-21 18:13

    Do not use [A-z], use [a-zA-Z]:

    ^[a-zA-Z]+([a-zA-Z\s-]*)[a-zA-Z]+$
    

    Otherwise, the [A-z] class will match some other non-letter symbols, too:

    Here is a demo on regex101.com.

    Just a note: [A-z] can sometimes be used to match all letters in POSIX-style regex when collation is set for a particular language.

    [[ "ABCEDEF[]_abcdef" =~ ([A-z]+) ]] && echo "${BASH_REMATCH[1]}" on Cygwin with LC_COLLATE="en_US.UTF-8" yields ABCEDF. If you set LC_COLLATE to C (on Cygwin, done with export), it will give the expected ABCEDEF[]_abcdef.

    0 讨论(0)
提交回复
热议问题