我有以下数组
names=( 12_1_3_4_NAME1 1_2_4_NAME2 2_1_name3 1_nAmE4)
我想删除前缀并有
names=( NAME1 NAME2 name3 nAmE4 )
我尝试了一些变体:
names=( "${names[@]/^\d+(?:\_\d+)/}" )
names=( "${names[@]//s*^\d+(?:\_\d+)+\s*/}" )
基于之前的答案:
Use ^ to match the beginning of the string.
Use \d+ to match any number of digits.
Use \. to match a literal . character
Put \.\d+ in a group with () so you can quantify it to match any number of them.
Use re.sub() to replace it with an empty string to remove the match.
Use a raw string so you can put literal backslashes in the regexp without having to escape them.
patt = re.compile(r's*^\d+(?:\.\d+)+\s*')
string = patt.replace('', string
)
没有成功!我不知道我应该如何在数组中执行它
这应该有效:
shopt -s extglob
names=("${names[@]//*([[:digit:]])_/}")