使用 PosgreSQL 正则表达式,您需要确定文本是否具有从某个序列开始的固定编号行数(不多也不少)。例如,如果文本中正好有 6 行相同的行,以数字 + // 开头:
texttexttext
1// texttexttext
2// texttexttext
3// texttexttext
4// texttexttext
5// texttexttext
6// texttexttext
texttexttext
texttexttext
texttexttext
texttexttext
现在我正在寻找这个表达式:
(\n[1-6][//|\\|.| |)][^\n]+){6}\n(\D[^\n]+\n)*((?!7))
但如果编号行之间有任意行,它会失败:
texttexttext
1// texttexttext
2// texttexttext
3// texttexttext
texttexttext
texttexttext
4// texttexttext
5// texttexttext
6// texttexttext
texttexttext
texttexttext
texttexttext
texttexttext
中间这样的行可以连续1到3行,这个顺序只能是1次。是否可以在正则表达式中考虑这种情况?
您可以简单地选择匹配数为 6 的行。这可以通过函数
regexp_matches
和横向交叉连接的组合来完成。例子:此查询将显示表中的行ID
t
,其中文本(列a
)正好包含以拉丁字母开头的三行a
。