use gnu match for a few regexes
split massive one-liner into reasonable parts