Detlef, thanks for this clear expose of your code snippet. I have been avoiding 
similar constructs because I never could find the time to understand it and the docs I 
have access to are just not clear enough on this. Your code does some of the things I 
am doing in Perl, and it does it with much less effort.

Uli Wienands

> ----------
> From:         Detlef Lindenthal
> Sent:         Tuesday, September 24, 2002 16:03
> To:   Georgia Citizen; [EMAIL PROTECTED]
> Subject:      Re: [MacPerl] Get text from X to Y in a string
> 
> Tony wrote:
> >>> I want to be able to grab a section of a string, starting at X and ending at Y.
> 
> Detlef Lindenthal wrote:
> 
> >> ##  Grab the amount like this:
> 
> >> $text = "The amount of the house is one hundred thousand dollars, and I cannot 
>afford that price.";
> >> $X = "amount of the house is";
> >> $Y = ",";
> 
> >> $text =~ m,$X(.*?)$Y,;
> >> print $1;  ## This prints: " one hundred thousand dollars"
> 
> 
> Tony wrote:
> 
> > I am not sure what the syntax is exactly, but it works great!
> 
> 
> The regex' technic  is not so difficult:
> 
> $text   contains your string
> =~   means: apply some regex ("regular expression" = search pattern or search and 
>replace pattern) on it
> m, ....... ,   means: what is between the two commata (or some other 2 characters) 
>shall be found (m stands for "match").
> $X and $Y are interpolatet; that means you could as well write
>                    $text =~ m'amount of the house is(.*?),';
> ..  means: any character except \n in this case
> ..* means: any count of those characters from zero to infinite
> ? means: as few as possible (= nongreedy search)
> (.*?) means: capture everything within these parens and return it named $1.
> 
> Learning is bliss.
> 
> 
> 
> 

Reply via email to