LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2010, 06:37 PM   #1
hawk__0
Member
 
Registered: Nov 2008
Posts: 105

Rep: Reputation: 15
Perl Regex matching HTML


I'm trying to find out how to extract the string between the 2 <title> tags: <title>this is what i want</title>.

I found lots of results but nothing I've tried works.. EG:
$page =~ m/<title>($.)<\/title>/gism;
 
Old 03-19-2010, 06:44 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by hawk__0 View Post
I'm trying to find out how to extract the string between the 2 <title> tags: <title>this is what i want</title>.

I found lots of results but nothing I've tried works.. EG:
$page =~ m/<title>($.)<\/title>/gism;
Why not use existing HTML parsing Perl modules ?
 
Old 03-19-2010, 07:57 PM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Maybe you want a substitution rather than a match:
Code:
$page =~ s#<title>(.*)</title>#$1#im;
Although as Sergei Steshenko suggests, you are better off using a proper HTML parser, since there are variations of the tags which will become unwieldy when using regular expressions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php preg_replace and perl regex matching aolong Programming 1 06-02-2009 05:32 PM
Perl only matching single-character regex patterns? Lordandmaker Programming 3 01-20-2009 08:59 AM
Matching two wildcards with perl and regex borinus Programming 3 09-09-2008 04:04 AM
Embedded regex matching in Perl GATTACA Programming 5 01-17-2007 09:16 AM
perl regex matching exodist Programming 2 11-15-2004 10:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration