-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
ap******@hotmail.com (Lydia Shawn) wrote in
news:12**************************@posting.google.c om:
hi there,
i want to extract the numbers from this example
input:
bla trigger3 trigger4 trigger1 blabla trigger1 5000.00 trigger3
trigger1 trigger2 trigger2 600.00 trigger4
trigger1 50.00 trigger4
i want to extract the numbers everytime they occur between trigger1 or
2 and trigger3 or 4.
so output:
5000,00
600,00
50,00
i thought i could use something like this
$return =~ /($trigger1|trigger2)(.*)(trigger3|trigger4)/si ;
but obviously i can't.. cause it doesn't work..
Well, think about it. In words, that pattern matches:
The variable $trigger1 *or* the string "trigger2"
followed by as much text as possible
followed by the string "trigger3" or "trigger4".
So it would match pretty much the whole string, eh?
You want to match
The string "trigger1" or "trigger2"
followed by possible whitespace
followed by digits (and maybe a decimal point?)
followed by more possible whitespace
followed by the string "trigger3" or "trigger4"
right?
/(trigger1|trigger2)
\s*
([\d.]+)
\s*
(trigger3|trigger4)/six;
The most important thing when writing regular expressions is to state
*precisely* what you're looking for, and then translate it into small
chunks that correspond to what Perl's RE engine can do, and then write
the expression.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPzWfKWPeouIeTNHoEQJXXwCg9yY/GXb8OXYXVVjlTtOL7QOA5/kAoJZU
LA2duAEVvyDkVmEZcIX0tcHq
=nJA/
-----END PGP SIGNATURE-----