in reply to regex match after pattern

Don't use regular expressions to parse HTML. Use a proper parser:
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $html = 'XML::LibXML'->load_html( string => << '__HTML__'); <form method="post" action="logout.lp" name="authform" id="logoutform" +> <input type="hidden" name="rn" value="-1383135969"> <form method="post" action="login.lp" name="authform" id="authform"> <input type="hidden" name="rn" value="-1383135969"> __HTML__ my $value = $html->findvalue('//form[@action="login.lp"]/input[@name=" +rn"]/@value'); print $value, "\n";
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: regex match after pattern
by marinersk (Priest) on Mar 12, 2015 at 16:05 UTC

    I've got just shy of four million reasons why a proper parser should be used for this purpose. But the inquisitive engineer in me wants to know: Under what conditions (not including fear of modules) might one justify not using the proper parser procedure?

      I'd use the regex approach if the input in question was generated from a known template that would never change, which means all the whitespace would always be in the sampe place. Or in a one-time script I'll never run again. Which makes it almost never. :-)
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Under what conditions (not including fear of modules) might one justify not using the proper parser procedure?

      When you know how to write and debug the regular expression yourself ;) and understand the risks

Re^2: regex match after pattern
by littleperl (Initiate) on Mar 13, 2015 at 14:58 UTC
    thank you for the quick response. Indeed why did I not opt for a parser, not sure, didn't use my head will probably is the most apropriate answer :) stepping away from the regex idea for this pattern search then.