shell 正则匹配

# shell 数字不支持\d ,只能使用[0-9]
if [[ "abcyyy13554221547HelloxxxWorld" =~ yyy([0-9]{11})(Hello)xxx(.*) ]]
 then
         echo The regex matches!
         echo $BASH_REMATCH       
         echo ${BASH_REMATCH[1]}  
         echo ${BASH_REMATCH[2]}
         echo ${BASH_REMATCH[3]}  
 fi


The regex matches!
yyy13554221547HelloxxxWorld
13554221547
Hello
World

posted @ 2022-08-16 02:11  shenshu  阅读(616)  评论(0编辑  收藏  举报