Re: Regular Expression ^^$$?
From: Eli the Bearded (*_at_eli.users.panix.com)
Date: 04/21/04
- Next message: Dances With Crows: "Re: how to securely copy a folder with many subfolders and files to a remote machine ?"
- Previous message: linux user: "Accented characters with RedHAt 9, aspell/ispell"
- In reply to: Doug O'Leary: "Regular Expression ^^$$?"
- Next in thread: Holger Petersen: "Re: Regular Expression ^^$$?"
- Reply: Holger Petersen: "Re: Regular Expression ^^$$?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 21 Apr 2004 20:36:22 +0000 (UTC)
In comp.os.linux.misc, Doug O'Leary <dkoleary@olearycomputers.com> wrote:
> The question apparently didn't give any information on the
> regex engine (perl/sed/awk, etc). All's it did was give the
> pattern and ask what does it match? It was apparently a
> multiple guess question only one answer of which could my
> cohort remember.
Well, that sucks becuase different regexp engines will handle it
differently.
> The pattern is: ^^$$.
In procmail '^^' matches at the very beginning(*) of a possibly multiline
string, like \A in perl, and $ matches a newline. So, '^^$$' would match
two blank lines at the start of the search space.
(*) And very end, hence '^^^^' to match an empty string. Procmail is weird.
$ cat > /tmp/test.rc
STRING='
Both lines above are empty.'
:0
* STRING ?? ^^$$
{ LOG='STRING matched.
'
}
^D
$ echo | procmail -m /tmp/test.rc
STRING matched.
$ procmail -v
procmail v3.22 2001/09/10
[...]
In perl, $$ will expand to the pid of the current process, and the double
caret will be treated the same as a single caret. So, '^^$$' would match
the pid of the perl process found at the start of a line.
$ perl -we 'print "Pid: $$\n";$_ = $$;if(/^^$$/){print "Matched\n"}'
Pid: 29968
Matched
$ perl -v
This is perl, v5.6.1 built for i686-linux
[...]
In grep (gnu grep at least), the ^ and $ will only be special in places
where they can possibly match the start or end of a line. So, '^^$$'
would match a line that contained exactly '^$'.
$ echo '^$' | grep -c '^^$$'
1
$ grep -V
grep (GNU grep) 2.5.1
[...]
Solaris grep (and ed on Solaris) behave like grep above.
That's several programs with three very different results.
Elijah
------
learned perl after his ed scripts got too hairy
- Next message: Dances With Crows: "Re: how to securely copy a folder with many subfolders and files to a remote machine ?"
- Previous message: linux user: "Accented characters with RedHAt 9, aspell/ispell"
- In reply to: Doug O'Leary: "Regular Expression ^^$$?"
- Next in thread: Holger Petersen: "Re: Regular Expression ^^$$?"
- Reply: Holger Petersen: "Re: Regular Expression ^^$$?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|