I'm trying to create a simple latex converter binding, just to find out python and the main regex, but I'm stuck trying to figure out why the code below does not work:
re.sub (r'\[\*\](.*?)\[\*\]: ?(.*?)$', r'\\footnote{\2}\1', s, flags=re.MULTILINE|re.DOTALL)
I want to convert something like:
s = """This is a note[*] and this is another[*] [*]: some text [*]: other text"""
in
This is a note\footnote{some text} and this is another\footnote{other text}
this is what I got (from using my regex above):
This is a note\footnote{some text} and this is another[*] [*]: note 2
Why is the pattern matched only once?
EDIT:
I tried the following statement:
re.sub(r'\[\*\](?!:)(?=.+?\[\*\]: ?(.+?)$',r'\\footnote{\1}',flags=re.DOTALL|re.MULTILINE)
Now it matches all the footnotes, but they do not match correctly.
s = """This is a note[*] and this is another[*] [*]: some text [*]: other text"""
gives me
This is a note\footnote{some text} and this is another\footnote{some text} [*]: note 1 [*]: note 2
Any thoughts on this?
source share