Perl how to stop regex pattern match when another pattern match occurs?
I have a pattern matcher code as like:
#!/usr/bin/perl
use strict;
use warnings;
open(HTML,"<source.html");
my $html = do {local $/; <HTML>};
$html =~ s/\n\ *//g;
while ($html=~m/<OPTION [^>]*>\D*([^<]+)/g){
开发者_运维问答 print $1;
print "\n";
}
close(HTML)
I want to do it until the file however I want to stop and break while loop it it sees any character that matches with a pattern that start with:
</S
How can I do that with Perl?
If you want to exit from a loop , you should use the last command:
last if ( $pattern ~= /^<\/S/ );
( my $to_search = $html ) =~ s{</S.*}{}s;
while ($to_search =~ m{<OPTION [^>]*>\D*([^<]+)}g) {
print("$1\n");
}
精彩评论