[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regexp not behaving as expected.
From: |
Neil R. Ormos |
Subject: |
Re: regexp not behaving as expected. |
Date: |
Mon, 18 Apr 2022 16:15:58 -0500 (CDT) |
slipbits wrote:
> I've got a problem with my use of regexp w/gawk
> and I can't seem to find out what I did
> wrong. When the first three characters on a line
> are "CC:" or " CC:" it is sometimes
> recognized, and sometimes not recognized, and I
> can't figure out what I've done wrong.
>
> The program is: [...]
>
> if ($0 ~ /^([:space:]\r)*(Subject|Date|CC|BCC|From|To):/) {
Try changing
[:space:]
in the two regexps to
[[:space:]]
Quoting the manual,
| A character class is only valid in a regexp
| *inside* the brackets of a bracket expression.
<https://www.gnu.org/software/gawk/manual/gawk.html#Bracket-Expressions>
The outer pair of brackets establish the bracket expression.
The inner pair of brackets are part of the "Character Class".
Good luck!