PYTHON REGEXP 用模式本身和替换来替换已识别的模式?
文本
-.1。这太棒了。2。谷歌刚刚毁了Apple.3。苹果毁了自己! pattern = (dot)(number)(dot)(singlespace)
假设您有 30 到 40 个句子,其中段落编号符合上述模式。
标签应替换为段落编号后面! 使用
re.sub()
我希望文本为:
</p> <p style="text-align: justify;">1. This is just awesome.</p> <p style="text-align: justify;">2. Google just ruined Apple.</p> <p style="text-align: justify;">3. Apple ruined itself!
Text-
.1. This is just awesome.2. Google just ruined Apple.3. Apple ruined itself!
pattern = (dot)(number)(dot)(singlespace)
Imagine you have 30 to 40 sentences with paragraph numbers in the above pattern. A <p>
tag should be replaced behind THE PARAGRAPH NUMBER! USING re.sub()
I want the text to be:
</p> <p style="text-align: justify;">1. This is just awesome.</p> <p style="text-align: justify;">2. Google just ruined Apple.</p> <p style="text-align: justify;">3. Apple ruined itself!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是正则表达式中匹配组的用途。
你想要的是这样的:
This is what matching groups are for in regular expresssions.
What you want is something like this: