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 doesn't appear at the begining or the end of a string. There doesn't 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 don't 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 doesn't appear at the begining or the end of a string. There doesn't 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 don't want to replace.
Cheers
WJ