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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 33418 in the body.
You can then email your comments to 33418 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#33418; Package grep. (Sun, 18 Nov 2018 04:06:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Peng Yu <pengyu.ut <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Sun, 18 Nov 2018 04:06:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Peng Yu <pengyu.ut <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: Convert from literal string to ERE?
Date: Sat, 17 Nov 2018 22:05:06 -0600
Hi,

I'd like to create an ERE expression for any literal string. I found
that "sed -e 's/\([][?+{|()\]\)/\\\1/g' " seem to work.

For example,
sed -e 's/\([][?+{|()\]\)/\\\1/g' <<< '\?+{|()[]'

Could anybody help confirm whether this will work for all the cases? Thanks.

-- 
Regards,
Peng




Information forwarded to bug-grep <at> gnu.org:
bug#33418; Package grep. (Sun, 18 Nov 2018 10:45:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Jackson <pj <at> usa.net>
To: bug-grep <at> gnu.org
Subject: Re: 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




Added tag(s) notabug. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Thu, 02 Jan 2020 04:05:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 33418 <at> debbugs.gnu.org and Peng Yu <pengyu.ut <at> gmail.com> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Thu, 02 Jan 2020 04:05:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 30 Jan 2020 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 59 days ago.

Previous Next


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