in reply to Which one is the better Regex?
The "pragmatic" answer may be different. 99.9+% of the time, extracting a title using a regex works just fine. It's not the bullet-proof way, but in my experience you'll see far fewer real problems than you'll see theoretical ones. If you're not sensitive to the risk, and want to avoid taking on the overhead of using a parser,
will work just fine. You may still need to strip leading or trailing whitespace, and convert any newlines to spaces.if ( $html =~ m|<title>(.*?)</title>|is ) { $title = $1; } else { # note that you failed to find a title }
If you're extracting much more that the title, though, I'd go with a parser.
|
|---|