Careful! There are a few gotchas in that snippet. First, there's a greedy match. If you have a string containing <p>one paragraph</p><p>another paragraph</p>, $2 will contain one paragraph</p><p>another paragraph. Besides that, if the regex succeeds, $2 won't contain what you expect. You can also leave off the default variable and certainly don't need to capture the paragraph tags. I'd prefer:
print $1 if m!<p>(.*?)</p>!;Of course, if there's anything more complicated than bare paragraph tags, you're better off using an HTML parser module.
In reply to Re: Re: =~ and substitutions
by chromatic
in thread =~ and substitutions
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |