fork download
  1. def remove_anchors(regex)
  2. pattern = regex.source
  3. pattern = pattern.gsub(/\A(?:\\A|\^)|(?:\\[zZ]|\$)\z/, '')
  4. return Regexp.new(pattern);
  5. end
  6. regex1 = /\A[a-z0-9\-_]+\z/
  7. puts "Abc_123_12".scan(regex1)
  8. regex2 = remove_anchors(regex1)
  9. puts "Abc_123_12".scan(regex2)
  10.  
Success #stdin #stdout 0.06s 9720KB
stdin
Standard input is empty
stdout
bc_123_12