Not (bracket) problem

exess

Newcomer
Joined
Jan 3, 2005
Messages
1
Hi all,

I've got quite a tricky one here. Here's the deal:

search : \[(url|URL)\](.*)\[/(url|URL)\]
replace : <a href="(\1)">...</a>

Problem is: when performing it in php sith ereg_replace(), it simply replaces everything between the first occurrence of "[ url ]" and the last one of "[ /url ]" i.e. if there are more than one pseudo-url in the string, it messes up (spaces are added in the quotes for pseudocode reasons).

Side note: when using my text editor, it doesn't mess up. Life is bitter...

What I'm looking for: a way to replace my wildcard (.*) with a "not bracket" expression. It succeeded in my text editor

search1: \[(url|URL)\]([^\]]*)\[/(url|URL)\]

but unfortunately not in PHP and I don't know why. I know PHP uses the Posix regexp mechanism. This is wild, I'd appreciate some help... ;)
 
This forum is for Microsoft .NET

Hi exess,

The first thing you should know is that this forum is for discussing the Microsoft .NET development environment, and that this regular expression subforum is for discussing regex's as pertains to .NET.

The second thing is that your search string above:

exess said:
search : \[(url|URL)\](.*)\[/(url|URL)\]
replace : <a href="(\1)">...</a>

looks good from my regex experience, which doesn't include php. Your replacement string looks good, also. Now, you may have problems, like you said, if there are occurrences of [/url] before the actual end of your string. The best thing to do is to find a forum for discussing php programming, where folks know about php regular expressions.

Happy regex'ing! :)
 
Back
Top