gpt4 book ai didi

Bash 非贪婪替换

转载 作者:行者123 更新时间:2023-12-04 05:21:14 26 4
gpt4 key购买 nike

说我有一个字符串

foo='teledunet&file=rotana_aflam&provider=rtmp&autostart=true&'

如果我想剪掉 file我可以做的参数
$ echo ${foo/&file=[^&]*}
teledunet

但正如你所看到的,搜索是贪婪的,并占用了字符串的其余部分。可以用它来代替非贪婪吗?

最佳答案

$ echo ${foo/&file*([^&])}
teledunet&provider=rtmp&autostart=true&

您可能需要 shopt -s extglob首先启用扩展的 glob 语法。

关于Bash 非贪婪替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13667328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com