Quote:
Originally Posted by meads
The author group stops building up when the dash - is encountered.
|
It's subtle, but to be perfectly accurate, for (?P<author>.+) - (?P<title>[^_]+) the author group keeps building up until it encounters the last space - hyphen - space group, not the first one. The matching is said to be "greedy" so in a filename like "author - something in the middle - title.txt" where there are
two space - hyphen - space groups, the first group (author) greedily builds up to be "author - something in the middle" and the last group is left with only the stuff after the last space - hyphen - space group. To reverse that, you can make the first group non-greedily match.
That's still no good if you want to ignore the middle text, which is why some of the regex groups get very complicated to optionally skip things and still match correctly.