I'm trying to find all the filenames ONLY, without the paths, from an SQL file by means of RegEx. Let's just say I'm trying to search and replace my findings using Adobe Brackets Replace function. What would be the RegEx to go about this?
The SQL file would contain hundreds of very long lines like so:
(493, 179, '_wp_attached_file', '2014/08/The_Image_Name_Here-004.jpg'),
(494, 179, '_wp_attachment_metadata', 'a:5:
{s:5:"width";i:365;s:6:"height";i:205;s:4:"file";s:31:"2014/08/The_Image_Name_Here-004.jpg";s:5:"sizes";a:6:
{s:9:"thumbnail";a:4:
{s:4:"file";s:31:"The_Image_Name_Here-004-139x100.jpg";s:5:"width";i:139;s:6:"height";i:100;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:
{s:4:"file";s:31:"The_Image_Name_Here-004-240x134.jpg";s:5:"width";i:240;s:6:"height";i:134;s:9:"mime-type";s:10:"image/jpeg";}s:15:"featured-medium";a:4:
{s:4:"file";s:31:"The_Image_Name_Here-004-230x160.jpg";s:5:"width";i:230;s:6:"height";i:160;s:9:"mime-type";s:10:"image/jpeg";}s:13:"featured-head";a:4:
{s:4:"file";s:31:"The_Image_Name_Here-004-365x193.jpg";s:5:"width";i:365;s:6:"height";i:193;s:9:"mime-type";s:10:"image/jpeg";}s:4:"icon";a:4:
{s:4:"file";s:29:"The_Image_Name_Here-004-81x87.jpg";s:5:"width";i:81;s:6:"height";i:87;s:9:"mime-type";s:10:"image/jpeg";}s:10:"icon-large";a:4:
{s:4:"file";s:31:"The_Image_Name_Here-004-120x131.jpg";s:5:"width";i:120;s:6:"height";i:131;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:10:
{s:8:"aperture";i:0;s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";i:0;s:9:"copyright";s:0:"";s:12:"focal_length";i:0;s:3:"iso";i:0;s:13:"shutter_speed";i:0;s:5:"title";s:0:"";}}'
),
Note: The above is just a sample of part of the content and is originally two lines but seperated into multiple lines for easier viewing
The expression that I tried is this:
/(?=\/|"|').*?(\.jpg)/g
And I expect to find these from the above sample:
The_Image_Name_Here-004.jpg
The_Image_Name_Here-004.jpg
The_Image_Name_Here-004-139x100.jpg
The_Image_Name_Here-004-240x134.jpg
The_Image_Name_Here-004-230x160.jpg
The_Image_Name_Here-004-365x193.jpg
The_Image_Name_Here-004-81x87.jpg
The_Image_Name_Here-004-120x131.jpg
But my result end up like this:
'_wp_attached_file', '2014/08/The_Image_Name_Here-004.jpg
"width";i:365;s:6:"height";i:205;s:4:"file";s:31:"2014/08/The_Image_Name_Here-004.jpg
"file";s:31:"The_Image_Name_Here-004-139x100.jpg
"file";s:31:"The_Image_Name_Here-004-240x134.jpg
"file";s:31:"The_Image_Name_Here-004-230x160.jpg
"file";s:31:"The_Image_Name_Here-004-365x193.jpg
"file";s:29:"The_Image_Name_Here-004-81x87.jpg
"file";s:31:"The_Image_Name_Here-004-120x131.jpg
Demo: http://refiddle.co/refiddles/54a94f7075622d09faf30c00
Any way I can get only the filenames (including the extension)?
If you are using regex's with lookbehind (so, not javascript) you can use this regex:
/(?<="|').+\.jpg(?="|')/g
Otherwise you can just use:
/[\w-]+\.jpg/g
The second one actually seems far more elegant to me, here it is at action.