Technology, Web & Business Forum



Welcome to the Technology, Web & Business Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.


Programming Discuss programming languages such as .NET, PHP, PERL, ASP, ColdFusion, C++


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-01-2008
Junior Member
 
Join Date: Apr 2008
Posts: 1
Default perl regex?

What's the best perl regular expression to pick up pattern in following HTML element:

<title> my perl expression </title>

an expression generic enough to be used for similar structures in a title.

thanks
miket thanks very much; unfortunately, i tried that but didnt work, is space a problem????
no wait, the one i had was like this:

<title>
my perl expression
</title>
eric thanks a lot, in fact im telling a robot how to pick up pattern in text so do not need to print, should have specified that in my question. i also made an error, my text was like this:

<title>
my perl expression
</title>

i tried the .* or (.*) but didnt seem to work.
s/<title>(.*)<\/title>

aha, i forgot the back slash....

eric thanks so much.
__________________
Powered by Yahoo! Answers
Reply With Quote
  #2 (permalink)  
Old 04-01-2008
Junior Member
 
Join Date: Apr 2008
Posts: 1
Default

Here is a simple regex for extracting the title, which is what you asked for. If you are looking for something more flexible, let me know.

my $title = '<title> my perl expression </title>';
$title =~ s/<title>(.*)<\/title>/$1/s;
print $title;

prints: " my perl expression "

EDIT: added /s to handle the multi-line issue

EDIT-2:
my $title = qq~
<title>
my perl expression
</title>~;
$title =~ s/<title>(.*)<\/title>/$1/s;

You might want to trim out any leading/trailing spaces/line breaks/carriage returns, etc...depending on your needs
__________________
Powered by Yahoo! Answers
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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