in reply to A regex question with 2 pieces of data

use strict; use warnings; use Regexp::Common; $_ = '<span class="style">28.56</span><span class="style">-1.22</span> +' . '<span class="style">-4.1</span><span class="style">04/02</span>' +; my ($f, $s) = /($RE{num}{decimal}).*?($RE{num}{decimal})/; print "$f&nbsp;&nbsp;$s\n"; __END__ 28.56&nbsp;&nbsp;-1.22

Abigail

Replies are listed 'Best First'.
Re: Re: A regex question with 2 pieces of data
by bilbozilla (Initiate) on Apr 08, 2003 at 00:24 UTC
    The first 2 sets of numbers will vary. How do I pull those? I should have been more clear .Could you please help?
      Just use Abigail-II's regex (courtesy of Regexp::Common) to pull them out of your data. If $data contains your data you want to get the numbers from, then something like
      my ($one, $two) = ($data =~ /($RE{num}{decimal}).*?($RE{num}{decimal})/);
      will put the first two numbers, regardless of what they are, into $one and $two. (Make sure to use Regexp::Common; in your script though before using the regex above!)

        And at some point here it the /s regex switch will be required if there are newlines in the data because dot doesn't match newline normall.y

        How do I put the Regexp:Common library on my server? Do I just include it as Common.pm in the CGI directory? The server is hosted by someone else. Please advise.