First of all, I know that you shouldn’t try to use regex to modify XML, this is a special case where I have to do that anyway and not use a parser.
I want this:
<nicetag_A-B>Teststring X-Y</nicetag_A-B>
To look like this:
<nicetag_>Teststring X-Y</nicetag_>
In short, I want to remove [any letter]-[any-letter] but only from the tag, not the actual content inside.
This is my regex so far:
Regex.Replace(inputString, @"(<.*?[a-zA-Z])\-([a-zA-Z].*?>)", "$1$2");
The problem with this is that it only works for the example above, if the tag would be named without A-B, the inner content (X-Y) would be replaced instead.
Any ideas?
Your example isn’t working, its replacing only the hyphen in the tag.
Try this here
and replace with
$1$2See it online here on Regexr