Alex Alex - 8 months ago 22
Ruby Question

Ruby: How do you escape from a regex with ']'

So I'm new to regex and I keep getting this warning and I don't know how to correct it:

madlib.rb:4: warning: regular expression has ']' without escape: /\[(\w*:*\w)]/

From this code: { |h, k|
puts "Give me #{k.sub(/\[(\w*:*\w)]/, "")}:"

print keys
puts "", $*[0].split(".")[0].gsub("_", " "),$*[0]).gsub(/\[(\w*:*\w)]/) { keys[$1] }

They way I call it seems simple at the moment, in the terminal I just put
madlib.rb Story1.txt
, but i'm going to be trying to implement it in a webpage using erb and sinatra, but I rather not have these warning pop up if I can help it.


Use \.


That should fix the issue