Possible Duplicate:
Split Ruby regex over multiple lines
If I have a really long regex in ruby, how do I separate it into multiple lines to make it more readable?
Is there a simple way to do this?
line.regexp = /^([^\ ]+) ([^\ ]+) \[(#{timestamp('%d/%b/%Y:%H:%M:%S %z')})?\] (#{ip_address}) ([^\ ]+) ([^\ ]+) (\w+(?:\.\w+)*) ([^\ ]+) "([^"]+)" (\d+) ([^\ ]+) (\d+) (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)"/
I can think of three ways to make your code more readable. Use:
/xmodifier and add comments with#.(?#comment_here)modifier.(?<year>\d{2,4})is useful for backreferencing or manipulating values afterwards.More information:
http://www.ruby-doc.org/core-1.9.3/Regexp.html