使用posix shell测试字符串中的正则表达式 [英] test for regex in string with a posix shell

查看:67
本文介绍了使用posix shell测试字符串中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试字符串是否与特定字符串匹配,是否将正则表达式与基本的(无bash或任何东西)posix shell脚本(在if语句中)匹配?

how can I test if a string matches a particular string matches regex with a basic (no bash or anything) posix shell script (in an if statement)?

推荐答案

您可以使用expr命令在POSIX shell中评估正则表达式:

You can use expr command to evaluate regular expression in a POSIX shell:

s='Abc'
expr $s : '^[[:alpha:]]\+'

3

expr返回匹配的字符数#在这种情况下为3.

expr returns # of matched characters which is 3 in this case.

这篇关于使用posix shell测试字符串中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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