2
Reply

C sharp regex replace first and last char of any word

Sumair Sheikh

Sumair Sheikh

Sep 9 2011 8:25 AM
2.3k
want to remove first and last character of any word by using regex.... FOr example..
(HELLO) (WORLD) will return === HELLO WORLD
and (HE/LLO) (WO/RLD) will return ====== HE/LLO WO/RLD
or //Hello WOrld/ will  return ========= Hello WOrld
or (HELLO) (W/ORLD) STACKOVERFLOW) will return === HELLO W/ORLD STACKOVERFLOW
(He(Lo)  Wo(R)ld will return ===== He(Lo  Wo(R)ld
I dun want to replace all parenthesis ..I wish to replace First and last parenthesis of any word.....
I m trying this ...
temp = Regex.Replace(temp, @"^[!@#$%^&*()_+=[{]};:<>|./?,\'""-]+", " ");
BUT this regex equation ONly remove FIRSt CHaracter IF FOund....

Answers (2)