Short question, but can’t make it work. I have a string:
COMPANY NAME - username (Name Surname).
What kind of regex will give me username (without spaces) from between - and ( in such example?
It’s ASP.NET C# if it makes any difference. Thanks in advance !
EDIT :
The company name is a string with possible spaces. Username is without spaces. The characters - and ( are present only in these 2 places. I thought it was 100% obvious since I gave such example.
If your line ends with a
.then the Regex is@"^.* - (.*?) \(.*\)\.$"Through the use of
.*?(the lazy quantifier) this Regex is quite resistant to strange “things” like the one I’m using as a test.Link with tests. Pass over each row to see the capture group.