[英]Bash string regex replace with “.*”
for a string 对于一个字符串
s='abc_somedef'
use regex replace (it works) 使用正则表达式替换(有效)
echo ${s//_some/}
use regex replace with .*
(it NOT works) 使用正则表达式替换为
.*
(不起作用)
echo ${s//^.*_some/}
I want the result to be def
我希望结果是
def
how I write it with bash internally (not sed/awk) ? 我如何在内部用bash编写它(而不是sed / awk)? maybe some escape char ?
也许一些逃逸字符?
Use this: 用这个:
echo ${s//*_some/}
Your version didn't match since it was trying to match a dot literally. 您的版本不匹配,因为它试图按字面意义匹配点。
UPDATE: 更新:
Chepner has correctly explained below that *
here is not part of a regex at all. Chepner在下面正确地解释了
*
这里根本不是正则表达式的一部分。 It is simply being used as a globbing character. 它只是被用作通配符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.