我才刚刚开始使用正则表达式,似乎有点卡住了!我在 TextSoap 中使用多行编写了批量查找和替换。这是为了清理我 OCR 的食谱,因为有成分和方向,我不能将“1”更改为“1.”,因为这可能会将“1 Tbsp”重写为“1. Tbsp”。
因此,我使用此代码作为查找来检查以下两行(可能带有额外的行)是否是下一个序列号:
^(1) (.*)\n?((\n))(^2 (.*)\n?(\n)^3 (.*)\n?(\n))
^(2) (.*)\n?((\n))(^3 (.*)\n?(\n)^4 (.*)\n?(\n))
^(3) (.*)\n?((\n))(^4 (.*)\n?(\n)^5 (.*)\n?(\n))
^(4) (.*)\n?((\n))(^5 (.*)\n?(\n)^6 (.*)\n?(\n))
^(5) (.*)\n?((\n))(^6 (.*)\n?(\n)^7 (.*)\n?(\n))
以及以下内容作为上述各项的替换:
$1. $2 $3 $4$5
我的问题是,虽然它可以按我的意愿工作,但它永远不会执行最后三个数字的任务......
我要清理的文本示例:
1 This is the first step in the list
2 Second lot if instructions to run through
3 Doing more of the recipe instruction
4 Half way through cooking up a storm
5 almost finished the recipe
6 Serve and eat
我希望它看起来像什么:
1. This is the first step in the list
2. Second lot if instructions to run through
3. Doing more of the recipe instruction
4. Half way through cooking up a storm
5. almost finished the recipe
6. Serve and eat
有没有办法检查上面的前一行或两行以向后运行?我已经向前看和向后看,那时我有些困惑。有人有办法清理我的编号列表或帮助我使用我想要的正则表达式吗?