tags:

views:

55

answers:

7

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

Any idea ?

Thanks in advance ,

Ish

A: 

Escape it, as it's a special character:

\.
David M
A: 

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`
Amarghosh
A: 

This should work just fine:

  [A-z._\-]+

Please be aware that you my have to escape that slash depending on your programming language.

Bobby
`A-z` will allow symbols from 91 thru 96 `[\\]^_\`` And hyphen need not be escaped if it is the first or last character in a character class
Amarghosh
+1  A: 
[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.-]
Tim Pietzcker
A: 

[a-zA-Z_\-.] should work. You might have to use a double slash, depending on the language you are using.

npinti
Escaping `.` isn't required inside a character class :)
Tatu Ulmanen
... and escaping `-` is required, unless it's the first or the last
unbeli
Thanks for the correction :D
npinti
A: 

. 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 \.

Upul
A: 

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

chiurox