PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Jul 18, 2019 3:15 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Sep 19, 2011 6:21 am 
Offline
Forum Newbie

Joined: Mon Sep 19, 2011 6:04 am
Posts: 1
Hello :),

I have a question regarding regular expressions.

On of the strings I want to proceed:
Syntax: [ Download ] [ Hide ]
The easiest way to get this going is to use this link: .


I used this expression before to replace, which was working, but now, since there is the [up]...[/up] statement in it, I get a problem:
Syntax: [ Download ] [ Hide ]
echo preg_replace("%\[url=([^\]]*)\]([^/[]*)\[/url\]%", "<a href=\"$1\">$2</a>");
 


I thought about something like this, but I cant get it do work.
Syntax: [ Download ] [ Hide ]
echo preg_replace("%\[url=([^\]]*)\]([^/[/url\]]*)\[/url\]%", "<a href=\"$1\">$2</a>");
 


Any ideas about that?

See you and thank you very much in advance
*Fuchur*


Top
 Profile  
 
PostPosted: Mon Sep 19, 2011 12:41 pm 
Offline
DevNet Master
User avatar

Joined: Mon Feb 24, 2003 11:12 am
Posts: 2572
Location: The Republic of Texas
I'm having trouble seeing what you're trying to do, but you can't negate a string. What you are doing is just for characters. Have a look at the lookaheads and lookbehinds:

http://www.regular-expressions.info/refadv.html

_________________
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


Top
 Profile  
 
PostPosted: Wed Dec 14, 2011 5:42 pm 
Offline
Forum Newbie

Joined: Wed Dec 14, 2011 5:33 pm
Posts: 1
Thanks for the link, this information helped me figure out my issue. I am still a little bit confused on whether I need to use a negative lookahead for a simple capture like this one though. Either way, I have seemed to resolve the issue that was preventing me from moving forward on the software that I am developing, at least for now. Hopefully I won't run into anymore coding issues like this one, and I can finish this project without any further complications. If anyone can help offer me some more clarity on the proper use of lookaheads and lookbehinds, I would be very grateful. This would probably save me from this type of snag in the future. Thanks.


Last edited by Dione on Thu Dec 22, 2011 11:27 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Dec 15, 2011 3:09 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Dec 15, 2011 2:40 pm
Posts: 85
Location: Nelson, NZ
For the record, you may not need a negative lookahead for this simple capture.
This regex:
Syntax: [ Download ] [ Hide ]
\[url=([^]]*)\](.*?)\[/url\]

Captures httpETC in Group 1 and MyUrl in Group 2
in
Syntax: [ Download ] [ Hide ]
[url=httpETC]MyUrl[/url]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group