My regex was a bit different. find [URL..blah] or [/URL..blah] and delete them with substitution.
#!/usr/bin/perl -w
use strict;
my $example = '[URL=http://img207.imageshack.us/my.php?image=dsc03598v
+t7.jpg][IMG]http://img207.imageshack.us/img207/2964/dsc03598vt7.jpg[/
+IMG][/URL]';
print "$example \n";
$example =~ s/\[\/*URL.*?\]//g;
print $example;
#prints
[URL=http://img207.imageshack.us/my.php?image=dsc03598vt7.jpg][IMG]htt
+p://img207.imageshack.us/img207/2964/dsc03598vt7.jpg[/IMG][/URL]
[IMG]http://img207.imageshack.us/img207/2964/dsc03598vt7.jpg[/IMG]
Update:I recommend Jeffrey Friedl's "Mastering Regular Expressions". This a "classic". But I figure this like nuclear weapons! The vast majority of regex problems can be solved by shooting the problem 1x or 2x or maybe even 3x with simplex regex'es in a sequence. Also I've found that the performance can be just as fast as a single complex regex (and sometimes faster)!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|