I want to match and replace a character sequence in the middle of a string, but the same sequence could appear at the begining or the end of the string as well and should be left alone. So for example:
Regex r = new Regex("a");
will match all occurences of "a" in a string, but:
Regex r = new Regex("^a");
will only match "a" if it occurs at the begining of the string, and:
Regex r = new Regex("a$");
will match it at the end. The trouble is I want to match "a" when it doesnt appear at the begining or the end of a string. There doesnt seem to be a way to say not begining and not end though? Does anybody know if such a thing is possible? I could use:
Regex r = new Regex(".a.");
but that will also match the character before and after the "a" which I dont want to replace.
Cheers
WJ
Regex r = new Regex("a");
will match all occurences of "a" in a string, but:
Regex r = new Regex("^a");
will only match "a" if it occurs at the begining of the string, and:
Regex r = new Regex("a$");
will match it at the end. The trouble is I want to match "a" when it doesnt appear at the begining or the end of a string. There doesnt seem to be a way to say not begining and not end though? Does anybody know if such a thing is possible? I could use:
Regex r = new Regex(".a.");
but that will also match the character before and after the "a" which I dont want to replace.
Cheers
WJ