There is a text file with the following content:

<br><br><span><a href="javascript:quiz_solution('некоторый текст')"><img src="/images/quiz_solution.png" title="решение задания"></a></span> </td> <td><img onclick="img_resize2(this);" style="cursor: pointer;" src="Data/2011/CalcFraction/CalcFraction_163c.gif" align="top"> 

How to parse 'some text' from here?

    4 answers 4

     #!/usr/bin/perl my $var=qq~ <td><img onclick="img_resize2(this);" style="cursor: pointer;" src="некоторый текст" align="top"> <table style="width:100%"> <tr valign="top"><td style="width:20px;"></td><td colspan="2"><div>не решено</div></td></tr> <tr valign="top"><td style="width:20px;"></td><td style="width:30px;"></td><td><input name="useranswer12047647" type="text" value="" disabled /></td></tr> </table> </td>~; ($var=~/(src="(.+)"\s+align)/mi) && (print $2) 
    • slightly changed the text of the file, messed up, sorry, please look - Anton Cherepkov
    • #! / usr / bin / perl my $ var = qq ~ <br> <br> <span> <a href="javascript :quiz_solution('sein text')"> <img src = "/ images / quiz_solution.png "title =" task solution "> </a> </ span> </ td> <td> <img onclick =" img_resize2 (this); " style = "cursor: pointer;" src = "Data / 2011 / CalcFraction / CalcFraction_163c.gif" align = "top"> ~; ($ var = ~ / (quiz_solution ('(. +)')) / mi) && (print $ 2); # or so if ($ var = ~ / (quiz_solution ('(. +)')) / mi) {print $ 2} - Anton Shevtsov
    • Thank you so much - Anton Cherepkov
    • And you could not write how the regulars will look like in order to get them out of <img onclick = "img_resize2 (this);" style = "cursor: pointer;" src = "some text" align = "top"> some text? Thank you once again, great! - Anton Cherepkov
    • #! / usr / bin / perl use strict; my $ text = qq ~ <img onclick = "img_resize2 (this);" style = "cursor: pointer;" src = "some text" align = "top"> ~; if ($ text = ~ / src = "(. +)" \ s + align = "top" /) {print $ 1} # or print $ 1 if ($ text = ~ / src = "(. +)" \ s + align = "top" /); # or ($ text = ~ / src = "(. +)" \ s + align = "top" /) && (print $ 1); # or slightly laconic my $ re = qr ~ src = "(. +)" \ s + align = "top" ~; # put the regular variable into the if ($ text = ~ $ re) {print $ 1} print $ 1 if ($ text = ~ $ re); ($ text = ~ $ re) && (print $ 1) - Anton Shevtsov

    If the text file contains only this piece, then you can use just such a regular file:

     $someText =~ /src="(.+?)"/; 

    If there is any other "src" in the text file, this regular expression will NOT work. But in the piece you just cited, there is only one "src"

      Parsing html regular expressions, to put it mildly, is not recommended. Especially since you are not familiar with them. For this there are other means.

      For example, there is a good parser in Mojolicious . As an example of his work, I recommend to look at mojocast / e5

      PS: If you still need a regular schedule, then it suffices to find everything inside single quotes, ie: qr / '([^'] +) '/

         use Mojo::DOM; my $html =<<TEXT; <br><br><span><a href="javascript:quiz_solution('некоторый текст')"><img src="/images/quiz_solution.png" title="решение задания"></a></span> </td> <td><img onclick="img_resize2(this);" style="cursor: pointer;" src="Data/2011/CalcFraction/CalcFraction_163c.gif" align="top"> TEXT my $dom = Mojo::DOM->new($html); my $img_1 = $dom->find('img')->[0]; print $img_1->attr('title') . ' : '. $img_1->attr('src'); __DATA__ решение задания : /images/quiz_solution.png