我必须从文件名中删除扩展名,我正在使用它:
preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename)
我想知道什么是sed相当于此。 我目前的做法是:
$(echo $filename | cut -f 1 -d '.')
但它并不是一直有效。
和
regex和sed是否有相同的表达式进行匹配,语法不同或表达式也会改变?
答案 0 :(得分:2)
以下是使用bash剪切文本的一些示例...
FileName="/var/www/html/index.html"
echo "${FileName}"
/var/www/html/index.html
echo "${FileName%/*}"
/var/www/html
echo "${FileName##*/}"
index.html
TmpVal=$(echo "${FileName%.*}")
echo "${TmpVal##*/}"
index
<强>描述... 强>