this expression describe "first letter should be alphabet and remaining letter may be alpha numerical". But i want it should allow special characters also like, when i enter "C#" it is raising error. i want to enter special character also and first letter should alphabet". help me thank you.
Did you mean `^[A-Za-z].*` ?
Zarel
2009-10-31 04:48:25
It is not taking as expression Mr. Joemoe
Surya sasidhar
2009-10-31 04:49:53
ya it is not accepting in property window
Surya sasidhar
2009-10-31 05:03:58
A:
^[A-Za-z](\W|\w)*
(\W|\w)
will ensure that every subsequent letter is word(\w
) or non word(\W
)
instead of (\W|\w)*
you can also use .*
where .
means absolutely anything just like (\w|\W)
Xinus
2009-10-31 04:42:09
@Xinus: the character class [\W|\w] means word characters, the | character, or non-word characters. If you changed your square braces to parenthesis, it would mean what you claimed. But it could still be more simply and more elegantly expressed.
Asaph
2009-10-31 05:10:44
@Asaph: I do not have much experience with regular expressions ... I think you are saying sounds logical, I am changing it to parenthesis ...
Xinus
2009-10-31 05:29:55
@paxdiablo: "^[A-Za-z]" would only match the first character, not the whole word. "^[A-Za-z].*" will work fine though, as Xinus also stated after his edit.
Marc Müller
2009-10-31 05:47:25
@Xinus This answer is likely not correct. The initial regular expression matches a valid C identifier. This solution will, unfortunately match "FOO\n\n\n" as well as "C#".
pst
2009-10-31 06:41:06
`(\W|\w)` is *not* the same as `.` since `\W` will always include newlines, whilst for `.` it depends on the mode.
Peter Boughton
2009-11-01 17:27:41
@Marc, if you're using the start anchor (^), I'm assuming (perhaps wrongly) that a missing end anchor ($) means just match at the start of the string. That's why I asked what the difference was. If it matches the whole string, then the start anchor would be superfluous.
paxdiablo
2009-11-02 04:29:39
+1
A:
This expression will force the first letter to be alphabetic and the remaining characters to be alphanumeric or any of the following special characters: @,#,%,&,*
^[A-Za-z][A-Za-z0-9@#%&*]*$
Asaph
2009-10-31 04:42:26
Surya sasidhar
2009-10-31 04:44:39
Asaph
2009-10-31 04:47:45
@Surya sasidhar: Do you want to allow spaces? Your original regex in the title appears to allow spaces.
Asaph
2009-10-31 04:48:53
@Xinus: No. * doesn't need to be escaped when it's within a character class.
Asaph
2009-10-31 04:49:54
+1
A:
How about
^[A-Za-z]\S*
a letter followed by 0 or more non-space characters (will include all special symbols).
Mark
2009-10-31 05:38:34