Trying to write a regex that can split title and author given the syntax:
Author Name – Title
The title can contain multiple “-“.
I have the following regex: ([^-]*) - (.*)
This works for most cases, e.g.
Douglas Adams - Life, The Universe & Everything
splits into Douglas Adams and Life, The Universe & Everything
but fails for double barrelled author names –
e.g. Ayize Jama-Everett - Some Book Title as I then get:
Author = Everett
So I want to change the exclusion group [^-] to exclude the group " - ", as hyphens in the name will not have spaces surrounding them.
How do I do this?
Looks like you need lazy quantifier:
First group will get minimum number of symbols before
-. The second will capture the rest. It’ll not match if there is no-in the string.Depending of how you’re using it. You can also force it match with whole string by adding start and end quantifiers: