shell 里的正则详解程序员

#!/bin/bash 
 
variable="This is a fine mess." 
 
echo "$variable" 
 
# Regex matching with =~ operator within [[ double brackets ]]. 
if [[ "$variable" =~ T.........fin*es* ]] 
# NOTE: 从bash V3.2开始,正则表达式不再用引号引起来
then
echo "match found" # match found fi
#!/bin/bash 
 
input=$1 
 
 
if [[ "$input" =~ "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]" ]] 
#                 ^ NOTE: Quoting not necessary, as of version 3.2 of Bash. 
# NNN-NN-NNNN (where each N is a digit). 
then 
  echo "Social Security number." 
  # Process SSN. 
else 
  echo "Not a Social Security number!" 
  # Or, ask for corrected input. 
fi

 

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/2498.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论