I want to allow (.) and (a-zA-Z) letters and _ and - , I have some problems with the (.) ,
Any idea ?
Thanks in advance ,
Ish
As everyone already said, if you enclose a set of characters (no need to escape in this situation) in square brackets, you are saying: "please allow these characters I'm putting inside. I found a reference video for you: Skip to 22-23 min
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_.-]
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.-]
.
Has a special meaning in regular expressions, it uses to denote any character. Therefore you need to use escape character.
So you need to use \.
This should work just fine:
[A-z._\-]+
Please be aware that you my have to escape that slash depending on your programming language.
Escape it, as it's a special character:
\.