bash 3.0支持进程内的[正则表达式]
使用下面的语法:
[[ string =~ regex ]]
样例及注意事项:正则表达式不能使用引号引起来,引起来后,bash将作为一个整体
regx_str="abcdefgfootballgame"
echo $BASH
#if [[ $regx_str =~ 'foot(ball)(.*)' ]]
if [[ $regx_str =~ foot(ball)(.*) ]]
then
echo The regex matches!
echo $BASH_REMATCH
echo ${BASH_REMATCH[1]}
echo ${BASH_REMATCH[2]}
fi
greet="Hello,World!"
if [[ $greet =~ [1-9] ]]; then
printf "$greet is a number\n"
else
printf "$greet is not a number\n"
fi