Minor RE style point: \a/\z or ^/$ pairs are the usual way to balance begin/end string, depending on whether or not you want to span linefeeds. So in this case \a might be better?