From: Oliver Andrich Date: 2005-12-07T08:07:35+09:00 Subject: Re: Question concerning multiline regexps and best practice ako... schrieb: > unless i do not understand the question, a regex option that allows > multiline matches might be used. Well, to better describe what I am currently dealing with, I post a snippet of python code with the regex. msg_rx = re.compile( "^\x01?" + "(?P[a-zA-Z]{3,4})(?P\\d{3,4}) " + "(?P\\d) " + "(?P[a-zA-Z]{1,3}) " + "(?P\\d{1,4}) " + "(?P.*)\r\n*" + "(?P.*)\r\n*" + "\x02" + "(?:(?P.*)=\\s*\r\n)?" + "(?P.*)" + "\x03.*" + "(?P\\d{2})(?P\\d{2})(?P\\d{2}) " + "(?P[a-zA-Z]{3}) " + "(?P\\d{2})", re.S ) This little "baby" does the job. As ruby doesn't have named groups in regexps, I have to add comment lines (?#...) to document the invidual groups. This would glutter the thing even more. Now ruby has these nice HERE documents, %r{...} and so on. I would be happy if I could achieve something like that. msg_rx = %r{ ^\x01? (?# comment for the line) ([a-zA-Z]{3,4})(?P\\d{3,4})\s (\\d)\s (?# comment for the line) ([a-zA-Z]{1,3})\s (?# comment for the line) (\\d{1,4})\s (.*)\r\n* (.*)\r\n* \x02 (?# comment for the line) (?:(.*)=\\s*\r\n)? (?# comment for the line) (.*) \x03.* (?# comment for the line) (\\d{2})(\\d{2})(\\d{2})\s (?# comment for the line) ([a-zA-Z]{3})\s (?# comment for the line) (\\d{2}) } Thinks looks a lot cleaner for me, but sadly the "\n" at the end of the lines are in my way. :) I could strip them, but if it would just "happen" it would be nicer. Hopefully, this makes my question a little clearer. Best regards, Oliver