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 Replace

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
GB
Hi

I want to write a regex to replace the _ character in framework generated control ids. Easy :) except I need the expression to match all instances of an _ except where it is the first character in the string. Can't work it out at all.

Obviously ^_ will match the first character if it is an underscore but how do I match all underscores in a string except if one is the first character?

Thanks

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Rob,
Did you get this working. If not can you post a couple of before and after test strings.
Marty
 
Yeah was being stoopid :) Using the framework Regex classes you can perform a replace starting from the specified position in the string thus something like
Code:
regex.Replace(string, replacement, -1, 1)
would replace all instances starting from the character in position 1 (the second in the string)...

Im sure there is someway using look ahead style stuff to write a regex which matches all instances of a charcter except if its in position 0 in the string, but i couldn't find it :)

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top