If you want to match any character to a character ( then this should work:
@"^.*?(?=\()"
If you need all the letters, then this should do the trick:
@"^[a-zA-Z]*(?=\()"
Explanation:
^ Matches the beginning of the string .*? One or more of any character. The trailing ? means 'non-greedy', which means the minimum characters that match, rather than the maximum (?= This means 'zero-width positive lookahead assertion'. That means that the containing expression won't be included in the match. \( Escapes the ( character (since it has special meaning in regular expressions) ) Closes off the lookahead [a-zA-Z]*? Zero or more of any character from a to z, or from A to Z
Link: Regular Expression Language - Short Link (MSDN)
EDIT : Actually, instead of using .*? as Casimir noted in his answer, it is easier to use [^\)]* . ^ , used inside a character class (a character class is a construction [...] ), inverts the value, so instead of "any of these characters" it means "any other than these characters." Thus, an expression using this construct will be:
@"^[^\(]*(?=\()"
source share