I'm trying to squash warnings in an open source project, and
/[\.\,\;\:\(\)\[\]\{\}\<\>\"\'\`\~\/\|\?\!\&\@\#\s\x00-\x1f\x7f]+/
is giving me
(irb):1: warning: character class has duplicated range
Are there any tools that automatically point out which parts of the regexp causes the overlap?
I don't know of any tool, but I've spotted the overlap: \s
contains \t
, \f
, \n
and \r
, so that overlaps with the \x00-\x1f
part.
So, unless there's a way to get Ruby itself to tell you that it found a "problem", you can write this regex as (removing all those unnecessary backslashes along the way):
/[.,;:()\[\]{}<>"'`~\/|?!&@# \x00-\x1f\x7f]+/
If you ever reach that point of desperation, I guess you could put outputting some debug info in Ruby source and rebuild. :) I believe this is the place where the warning is thrown:
https://github.com/ruby/ruby/blob/trunk/regparse.c#L1787
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With