Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Escape regexp metacharacters

10 views
Skip to first unread message

Ian Zimmerman

unread,
Sep 20, 2015, 12:34:01 PM9/20/15
to
Is there a filter type program that copies its stdin to its stdout, but
with all regexp metacharacters escaped? I do mean regexp, not glob.

I can certainly write a sed script to the same effect. It just seems a
generic enough task that someone must have already done it. :-P

--
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.

Thomas 'PointedEars' Lahn

unread,
Sep 20, 2015, 12:59:49 PM9/20/15
to
Ian Zimmerman wrote:

> Is there a filter type program [except sed & friends] that copies its
> stdin to its stdout, but with all regexp metacharacters escaped?

Doubtful, because there is no universal definition of “regexp
metacharacters”.

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Ed Morton

unread,
Sep 20, 2015, 1:27:20 PM9/20/15
to
On 9/20/2015 11:21 AM, Ian Zimmerman wrote:
> Is there a filter type program that copies its stdin to its stdout, but
> with all regexp metacharacters escaped? I do mean regexp, not glob.
>
> I can certainly write a sed script to the same effect. It just seems a
> generic enough task that someone must have already done it. :-P
>

No because there's BREs and EREs and PCREs and POSIX/non-POSIX and escaping RE
metachars doesn't meant the tool will work (e.g. sed '/re/' needs the /s escaped
inside re as well as the re metachars), etc.

If you want something that';ll work for sed, see

Ed Morton

unread,
Sep 20, 2015, 1:27:55 PM9/20/15
to
0 new messages