RUBY   16

lines to regex

Guest on 21st August 2022 08:30:52 AM

  1. #!/usr/bin/env ruby
  2. # Converts lines from a file into an alternation of regex.
  3. if ARGV.size == 0
  4.         puts "lines_to_array.rb <file>"
  5. else
  6.         lines = File.readlines(ARGV[0])
  7.         lines = lines.map do |line|
  8.                 line.strip
  9.         end
  10.         puts '/\\b(' + lines.join('|') + ')\\b/'
  11. end

Raw Paste


Login or Register to edit or fork this paste. It's free.