简体   繁体   English

Notepad++ 正则表达式从 Markdown 格式化脚注中删除字符

[英]Notepad++ Regex Remove Character from Markdown Formatted Footnote

This is a follow-up question to what was solved yesterday: Notepad++ Regex Replace Makeshift Footnotes format With Proper Markdown format这是昨天解决的问题的后续问题: Notepad++ Regex Replace Makeshift Footnotes format With Proper Markdown format

I managed to find a Regex to remove the offending semicolons in the main text area but by only cutting out the text and pasting back the result, which can only be done one by one.我设法找到一个正则表达式来删除主要文本区域中的冒犯分号,但只删除文本并粘贴结果,只能一个一个完成。 I'm not sure how this can be done, but the expert can tell me.我不确定如何做到这一点,但专家可以告诉我。

So I have footnote references in markdown format.所以我有 markdown 格式的脚注参考。 Two instances of the same thing:同一件事的两个例子:

[^1]:
[^2]:
.
.
.
[^99]:

I might not have 99 in a document but I wanted to show I need to match two digits here again.我的文档中可能没有 99,但我想表明我需要在这里再次匹配两个数字。 As I said, there are two instances of these numbered references in the text.正如我所说,文中这些编号的参考文献有两个实例。 One in the main text pointing to the footnote and the footnote at the end of the document.正文中的一个指向文件末尾的脚注和脚注。 What I need is deleting the semi-colons from the main text and leave the我需要的是从正文中删除分号并保留

[^3]:
[^15]:
etc.

references at the end intact.最后的引用完好无损。

Because the main text references come after a word or at the end of a sentence (ususally before the sentence-ending period), there is never a case a reference would start a sentence (even if they seem to appear there once or twice because of word wrap).因为正文引用出现在单词之后或句子的结尾(通常在句末句段之前),所以从不存在引用会开始一个句子的情况(即使它们似乎出现一次或两次,因为自动换行)。

I provided the exact opposite of my needs here: Click here for Regex101 website link我在这里提供了与我的需求完全相反的内容:单击此处获取 Regex101 网站链接

I put in the exact opposite of what I want because I already knew of the我输入的内容与我想要的完全相反,因为我已经知道

^

sign to match anything that is at the front of the line.签名以匹配行前的任何内容。 Now I would like to negate this, if possible, so that I would delete the semi-colons in the main text, not down at the bottom.如果可能的话,现在我想否定这一点,以便我删除正文中的分号,而不是在底部。

Of course, it is likely that my approach is not good and you'll come up with a completely different approach.当然,很可能我的方法不好,你会想出一个完全不同的方法。 Especially because there doesn't seem to be a NOT operator in Regex, if I read correctly.特别是因为如果我没看错的话,Regex 中似乎没有 NOT 运算符。

I repeat: the Regex101 example with the match and substitution is exactly the opposite of what I want.我再说一遍:带有匹配和替换的 Regex101 示例与我想要的完全相反。 I am not sure if you can play around in the substitution line to get the desired negative effect.我不确定您是否可以在替换线中玩耍以获得所需的负面效果。

I could have probably asked for removing the first occurence of semi-colons but I thought the important part of tackling the problem is that those items not to be matched are always at the start of the line, not the others.我本可以要求删除第一次出现的分号,但我认为解决问题的重要部分是那些不匹配的项目总是在行的开头,而不是其他的。

Thanks for any suggestions感谢您的任何建议

In Notepad++ you might use a negative lookabehind asserting not the start of the string to the left, and use \K to clear the match buffer matching only the colon that should be replaced by an empty string.在 Notepad++ 中,您可以使用否定的lookabehind 断言不是左侧字符串的开头,并使用\K清除匹配缓冲区,该缓冲区仅匹配应该被空字符串替换的冒号。

(?<!^)\[\^\d{1,2}]\K:

Explanation解释

  • (?<!^) Negative lookbehind, assert not the start of the start directly to the left (?<!^) Negative lookbehind, assert not the start start directly to left
  • \[\^ Match [^ \[\^匹配[^
  • \d{1,2} Match 1 or 2 digits \d{1,2}匹配 1 或 2 位数字
  • ] Match literally ]从字面上匹配
  • \K Forget what is matched so far \K忘记到目前为止匹配的内容
  • : Match a colon :匹配一个冒号

Regex demo正则表达式演示

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM