示例:
kids-and-babies
kids-girls-1224
beauty
dresses-281
christmas-gifts-for-him-3130
目标产出将是:
kids-and-babies
kids-girls
beauty
dresses
christmas-gifts-for-him
我需要删除尾随数字和短划线(如果存在)。如果存在的话我会删除那个后缀,但后来我被困在后面的短划线上。
答案 0 :(得分:4)
答案 1 :(得分:1)
例如,在.NET C#
中Regex.Replace(input, "-\d+", "");
答案 2 :(得分:0)
in perl:
perl -pe 's/-[\d]+$//' your_file
测试:
> cat temp
kids-and-babies
kids-girls-1224
beauty
dresses-281
christmas-gifts-for-him-3130
> perl -pe 's/-[\d]+$//' temp
kids-and-babies
kids-girls
beauty
dresses
christmas-gifts-for-him
>