Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Whats the php or perl expression to match a string?
Old 12-15-2009, 04:53 AM Whats the php or perl expression to match a string?
Average Talker

Posts: 15
Trades: 0
Whats the perl regular expression to match a string? Like, How to find
a string which begins with
<p align="right"><em>webs
and ends with
align="right" /></a>

i tried <p align="right"><em>webs*align="right" /></a> doesn't work.

reference:
http://perldoc.perl.org/perlre.html

thanks
needesigner.com is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-15-2009, 07:15 AM Re: Whats the php or perl expression to match a string?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I dont know anything about perl, but with php you should be able to use a regular expression like this (although regexp still isn't my strong point )
PHP Code:
"/^(<p align=\"right\"><em>webs).*(align=\"right\"></a>)$/" 
^ indicates what the match should start with, . (dot) means any character and * means zero or more of that character, $ indicates where the match should end.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 12-15-2009 at 07:18 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-15-2009, 02:34 PM Re: Whats the php or perl expression to match a string?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
^ indicates what the match should start with, . (dot) means any character and * means zero or more of that character, $ indicates where the match should end.
I'm not a regexp expert neither, but ^ and $ don't exactly means that.

In multiline mode, ^ means "beginning of the line" and $ "end of the line".
So, your pattern would need to be at the beginning of a line and to terminate the same line to be matched.

Only when you are working on a single line, does ^ and $ means what Mattias meant.

As you most likely will be using the multiline mode if you parse a full page, I'd recommend you to drop the ^ and $ characters of the regexp given the previous post.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-15-2009, 03:58 PM Re: Whats the php or perl expression to match a string?
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Explode the data by
<p align="right"><em>webs
and by
align="right" /></a>
and echo something like $NewVariable[1].

It would be easier if it was something like <h1>, because you could just explode h1> (which includes <h1> and </h1>) and just echo that.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 12-16-2009, 05:54 AM Re: Whats the php or perl expression to match a string?
lazcorp's Avatar
Average Talker

Posts: 22
Name: Martin
Trades: 0
Try this
'#<p align="right"><em>webs.*align="right"><\/a>)#mi'


All / must be escaped, if You only want to test match there is no need of brackets ()
And the edining 'mi' says: multiline, case insensitive.
lazcorp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Whats the php or perl expression to match a string?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41326 seconds with 12 queries