天天看点

jq中的正则

正则匹配表达式

\w \s \d \b
. 匹配除换行符以外的任意字符 
\w 匹配字母或数字或下划线或汉字 等价于 '[A-Za-z0-9_]'。 
\s 匹配任意的空白符 
\d 匹配数字 
\b 匹配单词的开始或结束 
^ 匹配字符串的开始 
$ 匹配字符串的结束
\w能不能匹配汉字要视你的操作系统和你的应用环境而定      

test 判断字符串是否符合规定的正则

rep = /d+/;
      rep.test('asdf45hgh435asd')
      #true

      rep = /^\d+$/
      rep.test('sfsdfsf5463434fsf')      

exec 获取匹配的数据

rep = /\d+/;
      str ='xiaosan23haoba34'
      rep.exec(str)
      #['23']      

-------------------------------------------