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