我试着写一些在匹配前会返回1个字符的正则表达式。例如
:record1: Has text here with "\n" as the end of line \n
however, there can be multiple line \n
and I dont know how many before I get to the next record \n
:record2: has some other date in it \n
我目前正在尝试查找记录1结尾的正则表达式如下所示
(\n)(?=:record2:)
我想抓住最后一个\ n,但我可以得到它的位置。关于如何在字符串匹配之前捕获字符的任何想法?
答案 0 :(得分:0)
因此,如果您不想将字符串拆分为\n:record:
(并删除数字),这将更简单,更快,那么您要找的是一个名为{{3} }:\\n\n(?=:record\d+:)
。
您可以在此处查看演示:lookahead