How to get only a filename (not full path) into $1, using the PERL, regular expressions

Posted by Scott on Stack Overflow See other posts from Stack Overflow or by Scott
Published on 2011-03-03T15:22:09Z Indexed on 2011/03/03 15:25 UTC
Read the original article Hit count: 202

Filed under:
|
|

I want to keep only the filenames (not full paths) and add the filename to some bbcode.

Here is the HTML to be converted:

<a href=/path/to/full/image.jpg rel=prettyPhoto><img rel=prettyPhoto src=/path/to/thumb/image.jpg /></a>

Notice I cannot have rel="foo" (no double quotes)..

Here is what I have in PERL, to perform the conversion:

s/\<a href=(.+?)\ rel=prettyPhoto\>\<img rel=prettyPhoto src=(.+?) \/>\<\/a\>/\[box\]$1\[\/box\]/gi;

This converts the HTML to:

[box]/path/to/image.jpg[/box]

But this is what I want as a result:

[box]image.jpg[/box]

The HTML must remain the same. So how do I change my PERL so that $1 contains only the filename?

© Stack Overflow or respective owner

Related posts about regex

Related posts about perl