View Single Post
Old 02-22-2011, 03:55 PM   #10
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by meads View Post
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.
Starson17 is offline   Reply With Quote