假设我想匹配一个具有完全相同数量的字符A和B的模式,这样恰好有n个A,然后恰好是n个B' s。 例如,可以匹配以下字符串。
另一方面,这些字符串无法匹配
为了解决问题,我正在考虑重复计数,所以我的尝试看起来像这样
egrep 'A{n}B{n}'
但是,当然,大括号内的重复次数n不能隐式定义。
虽然我知道如何编写程序来匹配它,但我在Mac终端上测试它,因此我试图利用egrep的任何可能的功能来编写一个句子模式。
所以任何人都可以帮我解决这个问题,任何帮助都将不胜感激。
答案 0 :(得分:0)
如果您有.dialog-box {
font-family: Roboto, Arial, sans-serif;
display: inline-block;
}
.toggle-button {
width: 100%;
min-width: 300px;
}
.order-button {
cursor: pointer;
margin-top: -22%;
font-size: 175%;
}
.move-field-down {
margin-top: 25%;
}
,那么您可以使用此递归PCRE正则表达式:
SELECT CONCAT('Change from ', OrgMatch, ' to ', [RefMatch Confidence]) AS Data,
Count(CASE WHEN [Date] = '2017' THEN 1 ELSE NULL END) as '2017',
Count(CASE WHEN [Date] = '2016' THEN 1 ELSE NULL END ) as '2016'
FROM t1 GROUP BY OrgMatch, [RefMatch Confidence];
否则,您可以使用gnu grep
grep -P '^(A(?1)?B)$' file
AB
AABB
AAABBB
此awk
使用awk '(n=index($0, "B")) && length(substr($0, 1, n-1)) == length(substr($0, n))' file
AB
AABB
AAABBB
函数查找第一个awk
,并提取2个子字符串,即所有B
和所有index
并打印每个记录As
子字符串的长度与Bs
子字符串的长度相同。
答案 1 :(得分:0)
两种替代GNU awk 方法:
- 使用awk '{ match($0,/^(A+)(B+)$/,a) }length(a) && length(a[1])==length(a[2])' file
函数:
FPAT
- 使用awk -v FPAT="A|B" '{ for(i=1;i<=NF;i++) { ($i=="A" && $(i-1)!="B")? a++:b++ } }a==b' file
变量来定义字段值
AB
AABB
AAABBB
输出(两种方法):
{{1}}