[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] How to escape a string into its regex form
From: |
Peng Yu |
Subject: |
Re: [bug-gawk] How to escape a string into its regex form |
Date: |
Sun, 8 Sep 2019 10:45:36 -0500 |
On 9/8/19, Wolfgang Laun <address@hidden> wrote:
> "match the string *exactly*"
> What's wrong with "=="?
>
> The gsub for enclosing metacharacters in brackets might also be written as:
> gsub( /[][$^*()+{}|.?/]/, "[&]", regex );
> There's no need to use octal escapes.
> And, just to be on the safe side, I'd include the solidus, in case someone
> wants this to generate code, i.e., the result should appear verbatim in an
> awk program.
This does not deal with ^ correctly. What is the best way to fix it? Thanks.
--
Regards,
Peng