Reputation: 213
I have string like this:
test- qweqw (Barcelona - Bayer) - testestsetset
And i need to capture Bayer word.I tried this regex expression ( between "-" and ")" )
(?<=-)(.*)(?=\))
Example: https://regex101.com/r/wI9zD0/2 As you see it worked a bit incorrect.What should i fix?
Upvotes: 1
Views: 54
Reputation: 11238
You don't need regex for that, you can use LINQ:
string input = "test - qweqw(Barcelona - Bayer) - testestsetset";
string res = String.Join("", input.SkipWhile(c => c != '(')
.SkipWhile(c => c != '-').Skip(1)
.TakeWhile(c => c != ')'))
.Trim();
Console.WriteLine(res); // Bayer
Upvotes: 0
Reputation: 854
Here's a different regex to do what you are looking for:
-\s([^()]+)\)
https://regex101.com/r/wI9zD0/3
Upvotes: 1