Rod McLaughlin


Don't mindlessly copy regular expressions from websites (15 dec 12)

http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know

The URL regex in this page leads to an infinite loop in Ruby 1.9.3 with Rails 3.2.9:

$ rails c

Loading development environment (Rails 3.2.9)
1.9.3p125 :001 > URL_REG = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

1.9.3p125 :002 >  LONG_URL = 
"http://www.google.com/hostednews/ap/article/ALccvGQ?docId=29faa2"

1.9.3p125 :003 > LONG_URL =~ URL_REG
(hangs forever)

 



Back
Portland London