Regular expression, How to allow combination of dot (period) and letters?

前端 未结 7 613
庸人自扰
庸人自扰 2020-12-31 08:30

I want to allow (.) and (a-zA-Z) letters and _ and - , I have some problems with the (.) ,

Any idea ?

Thanks in advance ,

Ish

7条回答
  •  情书的邮戳
    2020-12-31 09:15

    [A-Za-z_.-]
    

    is a character class that includes all the characters you mentioned. Inside a character class, it's not necessary to escape the ., and you can avoid escaping the - if you put it first or last.

    If numbers are ok, too, you can shorten this to

    [\w.-]
    

提交回复
热议问题