Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

match everything until parenthesis

Tags:

regex

r

Given a string str = "Senior Software Engineer (mountain view)"

How can I match everything until I hit the first parenthesis, giving me back "Senior Software Engineer"

like image 961
user1103294 Avatar asked Dec 13 '12 20:12

user1103294


2 Answers

you would use ^[^\(]+ to match that and then trim it to remove the trailing space

like image 147
DiverseAndRemote.com Avatar answered Oct 12 '22 03:10

DiverseAndRemote.com


^[^\(]*

[^\(] is a character class, which matches everything except for (, and * is a greedy match, which matches the class as many times as possible. The ^ at the beginning matches from the beginning of the string.

like image 36
Swadq Avatar answered Oct 12 '22 02:10

Swadq