So I have a list of vinyl records that I own, and I am trying to remove some text from their results off of discog, the strings can look something like this;
Artist - Title (12") (Warner Bros - WB1210)
Artist - Title (12", Promo) (Warner Bros - WB1212)
Artist - Title (Summer Mix) (12", Promo) (Warner Bros - WB1444)
Artist - Title (12", LP Album) (Warner Bros- - WB9449)
Artist - Title (12", Red) (Warner Bros - WB1211)
Artist - Title
I want to remove the last set of parenthesis so they read;
Artist - Title (12")
Artist - Title (12", Promo)
Artist - Title (Summer Mix) (12", Promo)
Artist - Title (12", LP Album)
Artist - Title (12", Red)
Artist - Title
I have tried this regex pattern, with no luck;
(?<=\(12"(.*)\)[ ]).*
If I just use (?<=(12").) everything after 12" is highlighted, so I assumed add (.)) would get everything between 12" and the closing parenthesis, obviously it is not. Any ideas?
You can use something simple like,
(.*) \(
See it working on regex101.com.
To handle the newly added case where there are no parens at all, you can just use code. If there is no match, just dump the original string. I wrote up a little code snippet using your sample strings.
string[] testStrings = new[] { "Artist - Title (12\") (Warner Bros - WB1210)", "Artist - Title (12\", Promo) (Warner Bros - WB1212)", "Artist - Title (Summer Mix) (12\", Promo) (Warner Bros - WB1444)", "Artist - Title (12\", LP Album) (Warner Bros- - WB9449)", "Artist - Title (12\", Red) (Warner Bros - WB1211)", "Artist - Title" };
Regex regex = new Regex(@"(.*) \(");
foreach (var s in testStrings)
{
Match match = regex.Match(s);
Console.WriteLine(match.Success ? match.Groups[1].Value : s);
}
This outputs
Artist - Title (12")
Artist - Title (12", Promo)
Artist - Title (Summer Mix) (12", Promo)
Artist - Title (12", LP Album)
Artist - Title (12", Red)
Artist - Title