the above expression is raise when user give first letter as white space and first letter should not be a digit and remaining letters may alpha numerical. i need when user give white space as a first character automatically it should trimed i need that one can u help me thank u
+3
A:
^\s*([A-Za-z]\w*)
Should do it. Just get group 1.
I'm not sure the language you are using since the question was tagged Asp.Net and C, I'm going to assume you ment C#, so here is a C# sample:
string testString = " myMatch123 not in the match";
Regex regexObj = new Regex("^\\s*([A-Za-z]\\w*)",
RegexOptions.IgnoreCase | RegexOptions.Multiline);
string result = regexObj.Match(testString).Groups[1].Value;
Console.WriteLine("-" + result + "-");
This will print
-myMatch123-
To the console window.
Ryan Cook
2009-11-09 06:00:14
hi Ryan Cook it is not triming i tested like " sasi" it is not tring as "sasi" i take a textbox i typed " sasi" and read in a string but it is agin taking " sasi" i need "sasi". is it is possible
Surya sasidhar
2009-11-09 06:12:59
Surya: I updated my post with the exact code needed to get the trimmed result. I ran it and it seems fine. I am thinking that you made a small mistake in the implementation or perhaps I am misunderstanding your request.
Ryan Cook
2009-11-09 06:18:36
ya it is working Mr. Ryan Cook thank u dude
Surya sasidhar
2009-11-09 06:24:54
+1
A:
Is it possible to Trim()
your input before giving it to your regex?
If you're looking for alpha-numerical, starting with non-numeric, you probably want:
\s*([A-Za-z][A-Za-z0-9]+)
If you allow one-character user names, change that plus to a star.
memnoch_proxy
2009-11-09 06:07:17