Reputation: 21955
I have input like this:
I want to get everything before the first parens, or just everything if there are none
I've tried this:
(.+)(?=\()
But that only works when there are parens, obviously. Then I tried this:
(.+)(?=\()?
But that just selects everything. Does anyone have a solution?
Upvotes: 0
Views: 77
Reputation: 174706
You could try the below regex.
^[^(]*
^
Asserts that we are at the start and [^(]*
matches any character but not of (
zero or more times. *
repeats the previous token zero or more times.
Upvotes: 1
Reputation: 26667
You can use a very simple regex as
^[^(]+
^
Anchors the regex at the start of the string.
[^(]
Matches anything other than (
. Quantifier +
matches one or more occurence of the presceding regex
Upvotes: 2