You are here: Technology, Web & Business Forum
: Web Development
: Programming
:
perl regex?
|
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++
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
|||
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 |
|
|||
|
|||
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 |



Linear Mode
