You should not use regex to parse html, of course, but this should separate the content you want. I have limited php knowledge, so this just illustrates the procedure.
$tags =
' <
(?:
/?\w+\s*/?
| \w+\s+ (?:".*?"|\'.*?\'|[^>]*?)+\s*/?
| !(?:DOCTYPE.*?|--.*?--)
)>
';
$scripts =
' <
(?:
(?:script|style) \s*
| (?:script|style) \s+ (?:".*?"|\'.*?\'|[^>]*?)+\s*
)>
.*?
</(?:script|style)\s*>
';
$regex = / ($scripts | $tags) | ((?:(?!$tags).)+) /xsg;
- Group1,
( , Group2)
- : replacement =\1. textwrap (\ 2)
textwrap , .
Perl (btw ):
use strict;
use warnings;
my $tags =
' <
(?:
/?\w+\s*/?
| \w+\s+ (?:".*?"|\'.*?\'|[^>]*?)+\s*/?
| !(?:DOCTYPE.*?|--.*?--)
)>
';
my $scripts =
' <
(?:
(?:script|style) \s*
| (?:script|style) \s+ (?:".*?"|\'.*?\'|[^>]*?)+\s*
)>
.*?
</(?:script|style)\s*>
';
my $html = join '', <DATA>;
while ( $html =~ / ($scripts | $tags) | ((?:(?!$tags).)+) /xsg ) {
if (defined $2 && $2 !~ /^\s+$/) {
print $2,"\n";
}
}