var reg d g= /^[a-zA-Z]$/中$是什么意思

c# - ^[A-Za-Z ][A-Za-z0-9 ]* regular expression? - Stack Overflow
Stack Overflow for Teams
A private, secure home for your team's questions and answers.
to customize your list.
This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.
The regular expression ^[A-Za-Z ][A-Za-z0-9 ]* describe "first letter should be alphabet and remaining letter may be alpha numerical". But how do I also allow special characters?
When I enter "C#" it is raising an error.
How do I enter a special character and first letter should alphabet?
12.5k1982110
9,56149115205
A lot of the answers given so far are pretty good, but you must clearly define what it is exactly that you want.
If you would like a alphabetical character followed by any number of non-white-space characters (note that it would also include numbers!) then you should use this:
^[A-Za-z]\S*$
If you would like to include only alpha-numeric characters and certain symbols, then use this:
^[A-Za-z][A-Za-z0-9!@#$%^&*]*$
Your original question looks like you are trying to include the space character as well, so you probably want something like this:
^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$
And that is my final answer!
I suggest taking some time to learn more about regular expressions. They are the greatest thing since sliced bread!
page (that site in general is very good).
1,28851426
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@#%&*]*$
118k17155171
^[A-Za-z ].*
593k15811721608
3,29873453
^[A-Za-z]\S*
a letter followed by 0 or more non-space characters (will include all special symbols).
112k160604886
First must be Alphabet and then dot not allowed in target string.
below is code.
string input = "A_aaA";
// The regular expression we use to match
Regex r1 = new Regex("^[A-Za-z][^.]*$"); //[\t\0x0020] tab and spaces.
// Match the input and write results
Match match = r1.Match(input);
if (match.Success)
Console.WriteLine("Valid: {0}", match.Value);
Console.WriteLine("Not Match");
Console.ReadLine();
This expression will check if 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@#%&\*]*$
3,02342339
^[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)
13.6k23100152
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By clicking &Post Your Answer&, you acknowledge that you have read our updated ,
and , and that your continued use of the website is subject to these policies.
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 var a 和 var a区别 的文章

 

随机推荐