I have a list that contains with entries that will be in 1 of the 3 formats:
Test Section - Main Series -
Test 2 Section - Test Section - Main Seris
Main Series - -
I am try to use a RegEX to remove the training -
from the lines. I came up with the following code to try and do it and it kind of works. It removed the double instance of dashes in the third f开发者_StackOverflowormat, leaves the second format alone, but ti does not remove the single instance of the dash in the first format.
foreach (var item in menuItems)
{
item.NameWithParents = Regex.Replace(item.NameWithParents, @"(\s-\s\s-\s)|(\s-\s[^a-zA-Z])", "").ToString();
}}
I had thought the first group would make it remove the double dash while the second group would remove the single dash but it is not. The output I get is:
Test Section - Main Series -
Test 2 Section - Test Section - Main Seris
Main Series
Why is the single instance not being removed?
精彩评论