我正在处理一堆引用图像文件名的文本文件。这些文件名被消毒(使小写字母和空格替换为连字符) - 但引用它们的文本不是。正则表达式:匹配指定字符串之间的所有匹配项
我需要转换的字符串是这样的:
(image: uploaded IMAGE.jpg caption: this is my caption)
(image: uploaded IMAGE copy.jpeg caption: this is my caption)
(image: IMG_6087.png caption: this is my caption)
(image: IMG_6087 copy.gif)
(image: IMG_9999_copy.jpg)
(image: somehow, a comma.jpg)
(image: other ridic'ulous characters!.jpg)
到:
(image: uploaded-image.jpg caption: this is my caption)
(image: uploaded-image-copy.jpeg caption: this is my caption)
(image: img_6087.png caption: this is my caption)
(image: img_6087-copy.gif)
(image: img_9999_copy.jpg)
(image: somehow-a-comma.jpg)
(image: other-ridiculous-characters.jpg)
这些字符串较大的文本块的部分,但都是在他们自己的线路,像这样:
This is not a short guide to write about art. Go in, out of the window, inside New York’s stars qualities, dreams and schemes. People are gathered together, brewing coffee — you have seen their faces? The artists in Manhattan.
(image: manhattan photo.jpg)
Drive till sunset and say goodbye to your body, because this is not a photograph. I saw sixteen americans, raised by wolves, probably lost in paradise city. I found your head — Do you still want it?
我正在使用Sublime文本,并计划做多个替换所有:
- 带空格
- 条字符不是字母数字或_或 -
- 变为小写
但我不能设法捕捉的两个分隔符之间的东西所有实例。
(?<=^\(image:)[what do I do here??](?=\.jpe?g|png|gif)
这会捕获整个文件名,所以我可以使用搜索将其设置为小写:'(?<=^\(image:)(。*?)(?= \。jpe?g | png | gif)'替换:'\ L $ 1' - 这样可以解决第3步 - 但是如何找到并用连字符替换所有空格? –