i have a csv file full of plain image links
eg : http://www.domain.com/galleries/big/gallery_69_1481.jpg,
i have over a thousand of them to convert to a gallery images in wordpress’s post content
i thought notepad ++ would be the easiest using regex. i cannot find anything that would allow me to prepend and append text on either end of the url to make it look like such
<a href='http://www.domain.com/galleries/big/gallery_69_1481.jpg' title='' rel='prettyPhoto[gallery-1]'>,
am i looking in the right direction or should i be looking for something else?
EDIT: my plain csv has this layout
"gallery_8_68.JPG,gallery_8_69.JPG,gallery_8_70.JPG,gallery_8_71.JPG,gallery_8_72.JPG,gallery_8_73.JPG,gallery_8_74.JPG,gallery_8_75.JPG,gallery_8_76.JPG,gallery_8_77.JPG,gallery_8_78.JPG,gallery_8_79.JPG,gallery_8_80.JPG,gallery_8_81.JPG,gallery_8_82.JPG,gallery_8_83.JPG",
and i want to make it look like
<a href='http://www.domain.com/galleries/big/gallery_69_1489.jpg' title='' rel='prettyPhoto[gallery-1]'>,
If you’re doing it through notepad, you can use the Find/Replace regex function to do that.
Find:
Replace with:
regex101 demo
[^,rn]
is a negated class (a negated class has the form[^ ... ]
). A negated class will match any character except those inside it. As such,[^,rn]
will match all characters except commas, carriage returns and newlines. I added the carriage return and newline so that multiple lines don’t get eaten into a single line (compare this with this).+
is a quantifier and means 1 or more occurrences of the previous pattern. So[^,rn]+
means one or more character which is not a comma, carriage return or newline.In the replace, every but the
$0
part is literal.$0
is the matched pattern, and will contain the link that was matched.Per your edit, you’ll have to add some more characters to the regex and put more literal string in your replace…
Find:
updated regex101
Make sure to uncheck the ‘Match case’ checkbox to match both
.JPG
and.jpg
.