C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Escaping text for use in a regex
From: Giuseppe D'Angelo (giuseppe.dangelo_at_[hidden])
Date: 2019-12-11 01:36:30


Il 10/12/19 14:54, Arthur O'Dwyer via Std-Proposals ha scritto:
> Btw, I should have mentioned Google RE2 among the state of the art. RE2
> basically treats regexes as strings (rather than forcing every regex to
> be "compiled" into a non-string object like std::regex).  RE2 does
> provide `re2::QuoteMeta()` which takes a string and returns a string and
> does exactly what you asked for.
> https://github.com/google/re2/blob/master/re2/re2.h#L444-L450

Many other languages / libraries provide escaping functions (I've
personally written QRegularExpression::escape(), targeting PCRE).

Perl itself provides quotemeta(), Python provides re.escape(), PHP has
preg_quote(), Ruby has Regexp.escape(), and so on. Notably, JS' proposal
for adding a regexp escape functionality was rejected, apparently citing
concerns regarding composition of escaped fragments:

> https://github.com/benjamingr/RegExp.escape/issues/37

My 2 c,

-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups