python正则匹配_Python正则表达式只匹配一次

我正在尝试创建一个简单的降价乳胶转换器,只是为了学习

python和基本的正则表达式,但我不知道试图弄清楚为什么下面的代码不起作用:

re.sub (r'\[\*\](.*?)\[\*\]: ?(.*?)$', r'\\footnote{\2}\1', s, flags=re.MULTILINE|re.DOTALL)

我想转换像:

s = """This is a note[*] and this is another[*]

[*]: some text

[*]: other text"""

至:

This is a note\footnote{some text} and this is another\footnote{other text}

这就是我得到的(使用上面的正则表达式):

This is a note\footnote{some text} and this is another[*]

[*]: note 2

为什么模式只匹配一次?

编辑:

我尝试了以下先行断言:

re.sub(r'\[\*\](?!:)(?=.+?\[\*\]: ?(.+?)$',r'\\footnote{\1}',flags=re.DOTALL|re.MULTILINE)

#(?!:) is to prevent [*]: to be matched

现在它匹配所有脚注,但它们没有正确匹配.

s = """This is a note[*] and this is another[*]

[*]: some text

[*]: other text"""

给了我

This is a note\footnote{some text} and this is another\footnote{some text}

[*]: note 1

[*]: note 2

有什么想法吗?

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542678.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Virtual Network (1) - How to use it in a guest

本文将讲述一个问题:kvm guest使用libvirt xml定义如何使用virtual network?1)nat, route ,isolated, open类型在host中定义virtual network会创建一个虚拟的bridge,相当于一个交换机。guest只需要连接到这…

java string做除法_如果用java来实现传统方式的除法,用String来保存结果,想精确多少位都行,那改怎么做?...

我会加分的,提个思路都行,目前做了个乘法和加法,但是现在对除法没有什么思路。以下是我编写的功能:publicclassCalculator{publicstaticStringmulti(Strings1,Strings2){if(s1nu...我会加分的,提个思路都行&#xff0c…

c语言数组的声明和初始化_C声明和初始化能力问题和解答

c语言数组的声明和初始化This section contains aptitude questions and answers on C language Declarations and Initialization. 本节包含有关C语言声明和初始化的适切性问题和解答。 1) What will be the output of following program ? int main(){int m10;int xprintf(…

python2和python3的默认编码_python2和python3哪个版本新

Python2 还是 Python3 ? py2.7是2.x系列的最后一个版本,已经停止开发,不再增加新功能。2020年终止支持。 所有的最新的标准库的更新改进,只会在3.x的版本里出现。Python3.0在2008年就发布出来,而2.7作为2.X的最终版本并…

html-css样式表

一、CSS:Cascading Style Sheet—层叠样式表,其作用是美化HTML网页。 样式表分类:内联样式表、内嵌样式表、外部样式表 1、内联样式表 和HTML联合显示,控制精确,但是可重用性差,冗余多。 例如:&…

java 栈 先进后出_栈先进后出,堆先进先出

1.栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。与C不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆。2.栈的优势是,存取速度比堆要快,仅次于直接位于CPU中的寄存器。但缺点是,存在栈中的数据大小与生…

c#给定二维数组按升序排序_在数组中按升序对数字进行排序| 8086微处理器

c#给定二维数组按升序排序Problem: Write a program in 8086 microprocessor to sort numbers in ascending order in an array of n numbers, where size n is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501. 问题&#xf…

使用python套用excel模板_Python自动化办公Excel-从表中批量复制粘贴数据到新表

1、模块安装 1)cmd模式下: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xlrd pip install -i https://pypi.tuna.tsinghua.edu.cn/simple openpyxl 2)如果有安装Pycharm,则在程序中操作如下: 菜单栏&…

在HubSpot是如何应对Fat JAR困境的

在七月底,Spring Boot和Dropwizard分别发布了1.4和1.0版本,它们都是基于Fat JAR的。随着人们更多地采用这些框架和微服务架构,Fat JAR成为了通用的部署机制。\\Fat JAR技术会将Java应用的所有依赖打包到一个bundle之中,便于执行&a…

给定数字的b+树创建_在C ++中找到给定数字中的两个的下一个和上一个幂

给定数字的b树创建Problem statement: 问题陈述: Find Next and previous power of two of a given number 查找给定数字中两个的下一个和上一个幂 Next power of two 下一个二的幂 Example(1):input: 22output: 32 ( as 32 is 2^5)Example(2):input: 54output…

java 字节数组作用_这段java代码中字节数组b起到了什么作用?

importjava.io.*;importjavax.swing.*;publicclassIOMonitor{publicstaticvoidmain(String[]temp){//TODO自动生成的方法存根byteb[]newbyte[2];try{FileInputStreamfisnewFileInput...import java.io.*;import javax.swing.*;public class IOMonitor {public static void main…

如何查看本地的崩溃log_过年回家,还怕抢不到票?程序员教你如何抢票

2019年接近尾声,距离春节回家的日子越来越近,26日起,2020年除夕火车票正式开售,抢票大战也进入白热化阶段。是否为某抢票 App 加速而烦恼,是否为车票“秒光而烦恼”。别慌,作为连“对象”都是 new 出来的程…

获取列表中包含的元素数 在C#中

Given a list, and we have to count its total number of elements using List.Count property. 给定一个列表,我们必须使用List.Count属性计算其元素总数 。 C#清单 (C# List) A list is used to represent the list of the objects, it is represent…

I00037 亏数(Deficient number)

数论中,若一个正整数除了本身之外所有因子之和比此数自身小,则称此数为亏数。亏数(Deficient number)也称为缺数,参见百度百科_亏数,或参见维基百科的Deficient number。亏数在OEIS中的数列号为A005100。 问…

hashmap转红黑树的阈值为8_面试必考的 HashMap,这篇总结到位了

点击蓝色“JavaKeeper”关注我哟加个“星标”,一起成长,做牛逼闪闪的技术人1 概述HashMap是基于哈希表实现的,每一个元素是一个key-value对,其内部通过单链表解决冲突问题,容量不足(超过了阀值)时,同样会自动增长.HashMap是非线程安全的,只适用于单线程环…

linux用户组管理命令_Linux用户和组命令能力问题和解答

linux用户组管理命令This section contains Aptitude Questions and Answers on Linux User and Group Commands. 本节包含有关Linux用户和组命令的 Aptitude问答。 1) Which of the following commands is used to create a new user in the Linux operating system? create…

Failed to start firewalld.service: Unit firewalld.service is masked.

2019独角兽企业重金招聘Python工程师标准>>> FireWall in Centos 7 masked How to resolve the error message belowFailed to issue method call: Unit firewalld.service is masked. The main reason a service is masked is to prevent accidental starting or e…

mysql第二个索引_MySQL高级第二章——索引优化分析

一、SQL性能下降原因1.等待时间长?执行时间长?可能原因:查询语句写的不行索引失效(单值索引、复合索引)CREATE INDEX index_user_name ON user(name);(底层做了一个排序)CREATE INDEX index_user_nameEmail ON user(name,email);查询关联join…

递归反转链表改变原链表吗_在不使用递归的情况下找到链表的长度

递归反转链表改变原链表吗Solution: 解: Algorithm to find length 查找长度的算法 Input: 输入: A singly linked list whose address of the first node is stored in a pointer, say head. 一个单链表 ,其第一个节点的地址存储在指针(例…

西瓜仿站高手v1.08官方正式版

2019独角兽企业重金招聘Python工程师标准>>> 西瓜仿站高手是一款绿色好用的由追风网络出品的网站模板批量下载软件,西瓜仿站高手是一款仿站工具,仿站神器。软件功能强大,能够帮你轻松帮你下载任意网站、任意模板,并且速…