I want to allow (.) and (a-zA-Z) letters and _ and - , I have some problems with the (.) ,
Any idea ?
Thanks in advance ,
Ish
[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.-]
This will do [a-zA-Z_.-]+
Outside the character class, ([]
), you need to escape the dot (\.
)as it is a meta character.
[a-z]+\.com #matches `something.com`
[a-zA-Z_\-.]
should work. You might have to use a double slash, depending on the language you are using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With