Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Help Needed

Status
Not open for further replies.

jonshin

Programmer
Jan 10, 2004
6
US
I want to strip all non-alpha numeric chars and replace the first char with "x" if it is a number.

I have figured out the stripping of non-alpha numberic chars with the regex below, but how do I replace the first char with "x" if it is numeric? I want to do both operations in the same regex.

Code:
string onid = Regex.Replace(m, @"[^\w]", "").ToLower();
if (Char.IsNumber(onid, 0))
{
    onid = "x" + onid;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top