正则表达式 – 使用加号前置文件名

前端之家收集整理的这篇文章主要介绍了正则表达式 – 使用加号前置文件名前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在一个巨大的文件中使用sed在所有出现的图像名称之前添加一个(加号).

这是一行的示例:

DAUSSI-H22-14K White Gold-Princess-1.00ct-G-SI1orH-VS2-EGL-mm-3.5,H22,7050,5720,3/5/2012 7:34,1,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5.html,Henri Daussi H22 Diamond Halo Engagement Ring-14K White Gold-Style:Princess-1.00ct-G-SI1 or H-VS2-EGL-Width: mm-Size:3.5,"Henri Daussi engagement ring with hand-matched side diamonds in a beautiful halo setting,totaling 1.40 carats. The image at left displays this ring with a 1.00 carat princess cut diamond. This setting can accommodate a variety of shapes and sizes. Please contact us on the range of possibilities of any ring.",14K White Gold,Princess-1.00ct-G-SI1 or H-VS2-EGL,3.5,Metal_Style_Width_Size,simple,/H22.jpg,Shown with a 1.00 carat princess cut diamond.,/H_22.jpg,Enabled,Taxable Goods,Not Visible Individually,No,Engagement Rings/Henri Daussi;;Designers/Henri Daussi,"ROUND,PEAR SHAPE,EMERALD CUT,MARQUISE,OVAL,RADIANT,PRINCESS CUT,HEART SHAPE,CUSHION CUT,ASSCHER CUT",.45-6.00 Carat,/H22.jpg

对于这一行,图像是/H22.jpg,我想将此字符串更改为/H22.jpg.

据我所知,所有图像都以/开头,但它是一个巨大的文件,我不能完全确定.我确定的一件事是之前有一个逗号(它是逗号分隔的.csv文件).所以我需要用[image_name] .extension替换[除dot之外的任何字符] [dot](.jpg | .gif | .png).

这是迄今为止我做过的最好的事情:

sed -ie 's/,\([a-zA-Z0-9/_]\+\)\(\.jpg|\.png|\.gif\)/,+\1\2/g' file.csv

但它不起作用.

试试这个:
sed 's#\(,\)\([^.,]\+\.\(jpg\|png\|gif\)\)#\1+\2#g' infile

说明:

s#...#...#g             # Substitute command. '#' is separator and 'g' is to apply it many times for 
                        # each line.
\(,\)                   # Match a comma,and save it as '\1'
[^.,]\+\.               # Match any characters until a '.' or ',' found.
\(jpg\|png\|gif\)       # Match extension.
\1+\2                   # Replace with: Comma,plus sign and the image name.
原文链接:https://www.f2er.com/regex/356898.html

猜你在找的正则表达式相关文章