Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 将多行字符串与shell匹配(正则表达式+;顺序)_Regex_Shell - Fatal编程技术网

Regex 将多行字符串与shell匹配(正则表达式+;顺序)

Regex 将多行字符串与shell匹配(正则表达式+;顺序),regex,shell,Regex,Shell,我想搜索下面给定的字符串与文件文本匹配 [zero or more white-space]AA[one or more white-space]AA[zero or more white-space] [zero or more white-space]BB[one or more white-space]BB[zero or more white-space] 匹配行的顺序应正确 BB BB other lines AA AA 注意:顺序不正确 BB BB other

我想搜索下面给定的字符串与文件文本匹配

[zero or more white-space]AA[one or more white-space]AA[zero or more white-space]
[zero or more white-space]BB[one or more white-space]BB[zero or more white-space]
匹配行的顺序应正确

BB    BB

other lines

AA AA
注意:顺序不正确

BB    BB

other lines

AA AA
无重复匹配

注:重复行匹配

  AA AA

 AA    AA
在“AA AA”和“BB BB”之间,可以包含零行或多行(任何字符串)

find=$(grep -e "\(^[[:space:]]*AA [[:space:]]*AA[[:space:]]*$\|[[:space:]]*BB [[:space:]]*BB[[:space:]]*\)" myfile.txt | grep -oP '^[[:space:]]*AA[[:space:]]*AA[[:space:]]*\s+[[:space:]]*BB[[:space:]]*BB[[:space:]]*$')
duplicate=$(sort $in_file | uniq -d | (grep "\(^ *AA \+AA *$\|^ *BB \+BB *$\)") )

if [[ -z $duplicate ]] && [[ ! -z $find ]] ; then
  echo 'OK'
else
  echo 'NOT OK'
fi
如果字符串中有空格
AA[space]AA
,则上面的脚本可以正常工作,但如果有空格的制表符类似
AA[space][tab]AA
则无法工作


我不能给\s+的问题
grep-oP

使用字符类
[:blank:]
(也包含选项卡)而不是
[:space:]
,或者如果可以使用像这样的ASCII字符类:
[\t]
使用字符类
[:blank:]
(也包含选项卡)而不是
[[:space:][]
,或者如果可能的话,使用像这样的ASCII字符类:
[\t]