garabik / grc

generic colouriser
http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
Other
1.9k stars 162 forks source link

case insensitivity needed #221

Open 1manfactory opened 2 years ago

1manfactory commented 2 years ago

Hello I want to check for "error", "Error" and "ERROR" in my log files. How can I make the regex case-insensitive. I can't add an "i" to the expression like in other regex installations. I could really need that. Great work regards Juergen

lnxbil commented 1 year ago

I just had the same problem and wrote a little script to generate the appropriate regular expression for any up/down-case combination:

#!/usr/bin/env ruby

if ARGV.size != 1
  puts "ERROR: Please provide a string"
  exit 1
end

str = ""
ARGV[0].split(//).each do |c|
  str += "[#{c.upcase}#{c.downcase}]"
end

puts str

which does what I needed ...

./updownregexpr Hello
[Hh][Ee][Ll][Ll][Oo]

Maybe it helps.