Home > Blockchain >  Notepad Regex Replace Makeshift Footnotes format With Proper Markdown format
Notepad Regex Replace Makeshift Footnotes format With Proper Markdown format

Time:08-29

In Word, I had to convert my footnotes to lines appearing at the end of each file to able to make changes in formatting. Some macro I found online was using braces and I ended up using also highlighting so I can see easily where my footnotes used to be. In this way, I have the following strings twice in my documents in the main text and also at the end of each document, sort of like makeshift endnotes.

=={1}==
.
.
.
=={99}==

I want to be able to match those instances in the text and convert them to proper markdown now. The problem is that the in-text format

[^1], [^2], etc.

will be different from what needs to come at the bottom with a semi-colon added:

[^1]:

etc.

So I'm guessing I'll have to live with replacing my old formatting with the new ones with semi-colons and deleting the semi-colons individually while I edit/clean up my text in the future. Without adding the semi-colon, it won't work.

My question is how to use the regex to match the two-digit strings with braces and equation marks.

This

==(\{d{1,2}\})==

did not work.

Also, as I am no pro, I would need the replacement as well. It probably will be

[^($1)]:

I reckon. Apparently, the equal mark doesn't have to be escaped.

Current format:

...some text...makeshift footnote in the format of

=={one- or two-digit number with no spaces in between}==

For example,

=={1}==

=={23}==

etc.

Desired result for all occurences recursively:

[^1]:

. . .

[^99]:

The markdown format is single square brackets with a caret and a number, also a semi-colon with the actual footnotes. Usually the number goes up to 42-45 maximum but it doesn't matter, the two digit regex is needed. As I said, the semi-colon will be needed in all instances.

Cheers

CodePudding user response:

You have just some errors in your regex, you forget to escaped the d for digit, it should be \d and the capture group must not include the curly braces.

Use:

  • Ctrl H
  • Find what: =={(\d{1,2})}==
  • Replace with: [^$1]:
  • TICK Wrap around
  • SELECT Regular expression
  • Replace all

Explanation:

=={             # literally
(\d{1,2})       # group 1, 1 or 2 digits
}==             # literally

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

  • Related