G+_Matthew Reardon Posted July 26, 2014 Share Posted July 26, 2014 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 More sharing options...
G+_L I Posted July 27, 2014 Share Posted July 27, 2014 I had success with: $content =~ s/.•(REGIONAL.•NOT AVAILABLE).•/$1/s; I had to get around G+'s formatting rules. Replace • with * ? Link to comment Share on other sites More sharing options...
G+_Matthew Reardon Posted July 28, 2014 Author Share Posted July 28, 2014 Columbia Fann and Lionel D thanks for the help. I just put a hold on "Learning Perl" at the local library! Link to comment Share on other sites More sharing options...
G+_Matthew Reardon Posted July 28, 2014 Author Share Posted July 28, 2014 Columbia Fann, Can u resend link to your code? When i opened it up nothing was there. Matthew Reardon Link to comment Share on other sites More sharing options...
G+_Joe Maruschek Posted July 29, 2014 Share Posted July 29, 2014 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 More sharing options...
Recommended Posts