如何将regexp与ash匹配? [英] How to match regexp with ash?

查看:145
本文介绍了如何将regexp与ash匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码适用于bash,但现在我需要它用于busybox ash,它显然没有"=〜"

Following code works for bash but now i need it for busybox ash , which apparrently does not have "=~"

keyword="^Cookie: (.*)$"
if [[ $line =~ $keyword ]]
then
bla bla
fi

有合适的替代品吗?

很抱歉,如果这是超级用户问题,则无法决定.

Sorry if this is SuperUser question, could not decide.

也没有grep,sed,awk等.我需要纯灰.

There is also no grep,sed,awk etc. I need pure ash.

推荐答案

对于这个特定正则表达式,您可能会遇到

For this particular regex you might get away with a parameter expansion hack:

if [ "$line" = "Cookie: ${line#Cookie: }" ]; then
    echo a
fi

模式匹配符号 +案例破解:

case "$line" in
    "Cookie: "*)
        echo a
    ;;
    *)
    ;;
esac

但是,这些解决方案的功能严格程度低于正则表达式,因为它们没有真正的Kleene星*(仅.*),并且您应该真的在该系统上安装一些更强大的工具(像Python这样的真正编程语言?),否则您将遭受 痛苦.

However those solutions are strictly less powerful than regexes because they have no real Kleene star * (only .*) and you should really get some more powerful tools (a real programming language like Python?) installed on that system or you will suffer.

这篇关于如何将regexp与ash匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆