Project

General

Profile

Actions

Feature #13048

open

Better way to do Regexp.new(Regexp.escape("some string"))

Added by justcolin (Colin Fulton) over 7 years ago. Updated about 7 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:78714]

Description

It is relatively common to call Regexp.new(Regexp.escape("some string")) or Regexp.new(Regexp.quote("some string")) in Ruby (a quick search turns up over half a million matches in Github). However, these seems rather cumbersome. It would be nice to have a class instance method on Regexp and/or an instance method on String to go directly to an escaped regular expression.

Personally I'd rather see #to_regexp added to String. This would not overlap with the functionality that Rexexp.new("string") provides since that doesn't quote the String.

It would also be good to see 9846 addressed along with this request so one could more easily duck type a method to accept both Regexp and String arguments.

Thoughts?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0