GNU bug report logs - #33418
Convert from literal string to ERE?

Previous Next

Package: grep;

Reported by: Peng Yu <pengyu.ut <at> gmail.com>

Date: Sun, 18 Nov 2018 04:06:01 UTC

Severity: normal

Tags: notabug

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Jackson <pj <at> usa.net>
To: 33418 <at> debbugs.gnu.org
Subject: bug#33418: Convert from literal string to ERE?
Date: Sun, 18 Nov 2018 04:44:16 -0600
Hi Peng,

I do not know your goal to "create an ERE expression for any literal string" means.

But what your "sed -e 's/\([][?+{|()\]\)/\\\1/g' " does is to prefix any of the characters in
the set '\?+{|()[]' with a backslash ... so if that's what you want, then I think you have it.

I am a bit surprised that this pattern works, as the [...] class lacks a closing ']' character.

The following alternative is shorter, does the same thing, and I find less surprising:

sed -e 's/[]\\[?+{|()]/\\&/g'

-- 
                Paul Jackson
                pj <at> usa.net




This bug report was last modified 5 years and 199 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.