I have this string:
City – This is some text. This is some more – and continues here.
I would like to split the string at the first ‘ – ‘ to find ‘city’ (just a sample word, it can be other words as well). Plus to find the rest of the text after ‘ – ‘.
I constructed this expression:
(^[\D\W\S]*)( - )([\D\W\S]*)
But this finds the last occurrence of ‘ – ‘ instead of the first one.
How can I stop at the first occurrence ?
The simplest solution would be to explicitly forbid the dash to be part of the first group:
Explanation:
However, this would fail if your string could contain a dash in the first group (just not surrounded by spaces). If that’s the case, then you can make use of lazy quantifiers:
Explanation: