You don't necessarily need the s-modifier here, only if you want to use the dot to match newline characters:
#!/usr/bin/perl use strict; use warnings; my $string = << "STRING_END"; <TITLE> RESULTADOS Y CLASIFICACIONES DE LA NBA </TITLE> STRING_END print "matched without modifier\n" if ($string =~ m{<TITLE>[^<]*RESULTADOS[^<]*</TITLE>}); print "matched with s modifier\n" if ($string =~ m{<TITLE>.*?RESULTADOS.*?</TITLE>}s);
Note that both these solutions are imperfect, the first will not work for nested tags and the second will match if the keyword is anywhere between the first <TITLE> and the last </TITLE>, even if it's outside a title, e.g. <TITLE>something</TITLE>RESULTADOS<TITLE>else</TITLE> will match. Which is why regexes are usually a bad solution for this kind of problem, it would be better to parse the SGML and check the contents of TITLE nodes directly.
In reply to Re: //s modifier
by tirwhan
in thread //s modifier
by kettle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |