|
|
Subject: regexp to match $100
From: Glenn Jackman
Date: 11/8/2007 2:39:24 PM
At 2007-11-08 02:53AM, "Helmut Giese" wrote:
> On Thu, 08 Nov 2007 05:18:55 -0000, "vinayak.mdesai@gmail.com"
> <vinayak.mdesai@gmail.com> wrote:
>
> >Hi,
> >
> >I am bit confused here...
> >
> >% regexp \$100 \$100
> >0
> >% regexp \$100 "\$100"
> >0
> >% regexp $100 "\$100"
> >can't read "100": no such variable
> >% regexp \$100 $100
> >can't read "100": no such variable
> >%
> Hi,
> if you can put your RE pattern into braces life is usually much
> easier. Try
> regexp {\$100} \$100
The reason is that the "$" is a RE constraint char (match end of line),
so is has to be escaped in your regex. If you don't want to brace the
regex you have to escape the escape:
% set str {$100}
$100
% regexp {\$100} $str ;# match a dollar sign and the digits 1, 0, 0
1
% regexp \\\$100 $str ;# as above
1
% regexp \$100 $str ;# match end-of-line followed by 1, 0, 0 (impossible)
0
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
|