A human way to define regular expressions?

Posted by chetan on September 05, 2013 in misc

Dear lord, I hope no one is actually using this in production.

pattern = Hexpress.new.
  start("http").
  maybe("s").
  with("://").
  maybe { words.with(".") }.
  find { matching { [word, "-"] }.multiple }.
  has(".").
  either("com", "org").
  maybe("/").
  ending
 
pattern.to_r #=> /^http(?:s)?:\/\/(?:(?:\w)+\.)?([\w\-]+)\.(?:com|org)(?:\/)?$/

via Hexpress by krainboltgreene.