csv逗号分隔的从普通网址到超链接的网址转换

编程入门 行业动态 更新时间:2024-10-11 17:26:57
本文介绍了csv逗号分隔的从普通网址到超链接的网址转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个包含纯图片链接的 csv 文件

i have a csv file full of plain image links

例如:http://www.domain/galleries/big/gallery_69_1481.jpg,

我有超过一千张图片可以转换为 wordpress 帖子内容中的图库图片

i have over a thousand of them to convert to a gallery images in wordpress's post content

我认为记事本++是最容易使用正则表达式的.我找不到任何可以让我在 url 的任一端添加和附加文本以使其看起来像这样的内容

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/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?

我的普通 csv 有这个布局

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",

我想让它看起来像

<a href='http://www.domain/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.

查找:

[^,\r\n]+

替换为:

<a href='$0' title='' rel='prettyPhoto[gallery-1]'>

regex101 演示

[^,\r\n] 是一个否定类(否定类的形式为 [^ ... ]).否定类将匹配任何字符除了里面的字符.因此,[^,\r\n] 将匹配除逗号、回车和换行符以外的所有字符.我添加了回车和换行符,这样多行就不会被吞入一行(比较 this与 this).

[^,\r\n] is a negated class (a negated class has the form [^ ... ]). A negated class will match any character except those inside it. As such, [^,\r\n] 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).

+ 是一个量词,表示前一个模式出现 1 次或多次.所以 [^,\r\n]+ 表示一个或多个不是逗号、回车或换行符的字符.

+ is a quantifier and means 1 or more occurrences of the previous pattern. So [^,\r\n]+ means one or more character which is not a comma, carriage return or newline.

在替换中,除了 $0 部分之外的所有部分都是文字.$0 是匹配的模式,将包含匹配的链接.

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...

查找:

[^,\r\n"]+\.JPG

<a href='http://www.domain/galleries/big/$0' title='' rel='prettyPhoto[gallery-1]'>

更新了 regex101

确保取消选中Match case"复选框以匹配 .JPG.jpg.

Make sure to uncheck the 'Match case' checkbox to match both .JPG and .jpg.

这篇关于csv逗号分隔的从普通网址到超链接的网址转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 14:09:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1173701.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   逗号   超链接   csv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!