#!/usr/bin/perl use Modern::Perl; my $capture; my $SFS = '<big><a name="hit men for hire" style="font-weight:bold;">H +it Men</a></big>'; # *1 my $regex = qr#<a name="([^"]+)#; # *2 if ( $SFS =~ /$regex/ ) { $capture = $1; say "\$capture: $capture" }else { say "No match"; } # $capture: hit men for hire
*1: Use of a style or span tag, among others, is legit... and a complication for which you'll want to allow unless you can be absolutely positive from now till the heat death of the universe, that no such element will appear in the hmtl you're parsing.
*2: The regex uses a negated character class which matches one or more of anything that is not a double-quote. The definitive end of the text *3 in an <a name="... element is the closing quote which matchs the opening quote. It may be single or double, but must match. So use that fact in your regex; write your regex specifying ONLY the minimum required to satisfy your spec; anything extra is just an invitation to error.
*3: The style component of the tag is, of course, text, but within what I understand to be the common meaning in OP's context, only the quoted portion is "text;" the style component is not what being described.
For a better understanding of regexen, see the relevant section in Tutorials, perlretut and similar.
In reply to Re: How do I select text between two bits of text?
by ww
in thread How do I select text between two bits of text?
by sdyates
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |