Jump to content

Can you help with the following code?


G+_Matthew Reardon
 Share

Recommended Posts

Can you help with the following code? It downloads a webpage and then I want to extract all the text between '000' and 'NOT AVAILABLE'.    I'm trying to use regular expressions in order to force myself to learn more about them.  I am trying to use the look behind and look ahead operators.  I'm not really sure why it's not working. Any help would be greatly appreciated.  Thanks.

 

http://pastebin.com/u0DBJmD0

 

 

Regex

http://pastebin.com/u0DBJmD0

Link to comment
Share on other sites

I think you can do what you want with just one match operator.  It turns out that perl sets some special variables after it does a successful match.  So if you put some parenthesis around the text you want, perl will put that into the special variable $1 for you to use. For example:

 

my $source = "blah blah blah blah BEGIN This is what I want. END blah blah blah blah ";

 

$source =~ /BEGIN(.*)END/;

 

print $1 . "\n";

 

In my example, I set up a string where I want a piece that is between the words BEGIN and END.  So I set up my regular expression, but I put (.*) in the middle, which should match 0 or more characters between the two words, but it puts the results of the match into variable $1.

Link to comment
Share on other sites

 Share

×
×
  • Create New...