我正在處理一堆引用圖像文件名的文本文件。這些文件名被消毒(使小寫字母和空格替換爲連字符) - 但引用它們的文本不是。正則表達式:匹配指定字符串之間的所有匹配項
我需要轉換的字符串是這樣的:
(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步 - 但是如何找到並用連字符替換所有空格? –