寻找正则表达式以查找页脚元素

huangapple go评论39阅读模式
英文:

Looking for regex to find footer elements

问题

以下是翻译好的部分:

我想使用正则表达式来搜索epub中的所有页脚示例,如下所示:

<p class="calibre1">2  <>  GENERAL INTRODUCTION </p>

更一般的格式如下:

<p class="calibre1">[1-1000中的页码]["  <>"][章节标题]</p>

我的目标是使用calibre的正则表达式来查找所有这种页脚示例并删除它们,但我尝试了以下表达式,没有一个可以找到上面的示例:

<p class="calibre1">[0-9]  <>[^>] </p>
<p class="calibre1">[0-9]  <>  [\w] </p>
甚至一般的:
<p class="calibre1">[\w--[\d_]]</p>
<p class="calibre1">[0-9] [.]</p>
<p class="calibre1">[0-9] *[.]</p>
<p class="calibre1">[0-9][*.]</p>

我对正则表达式很陌生,正在绞尽脑汁。请帮助我理解。
英文:

I would like to use regex to search for all instances of a footer in a epub like the following sample:

<p class="calibre1">2  <>  GENERAL INTRODUCTION </p>

of the more general format:

<p class="calibre1">[page number from 1-1000]["  <>"][Title of section]</p>

My goal is to use calibre's regex to find all instances of that footer and delete them but I've tried these expressions and none of them work to even find the one above example:

<p class="calibre1">[0-9]  <>[^>] </p>
<p class="calibre1">[0-9]  <>  [\w] </p>
and even the general:
<p class="calibre1">[\w--[\d_]]</p>
<p class="calibre1">[0-9] [.]</p>
<p class="calibre1">[0-9] *[.]</p>
<p class="calibre1">[0-9][*.]</p>

I'm new to regex and am pulling my hair out. Please help with my (mis)understanding.

答案1

得分: 0

这应该适用于您想要的内容:

^<p[ \t]*class="calibre1">[0-9]+[^<]*<>[^<]*<[/]p>$
英文:

This should work for what you want:

^<p[ \t]*class="calibre1">[0-9]+[^<]*<>[^<]*<[/]p>$

答案2

得分: 0

请尝试以下代码:

^<p class="calibre1">\d{1,4}.*</p>$

解释:

  • ^ - 锚定到行的开头
  • <p class="calibre1"> - 要匹配的实际文本
  • \d{1,4} - 匹配1到4位数字
  • .* - 然后匹配零个或多个字符
  • <\p> - 直到闭合标签
  • $ - 锚定到行的末尾
英文:

Please try this:

^&lt;p class=&quot;calibre1&quot;&gt;\d{1,4}.*&lt;/p&gt;$

^ - Anchor to the start of the line
&lt;p class=&quot;calibre1&quot;&gt; - Actual text to match
\d{1,4} - match 1 to 4 digits
.* - then zero or more characters 
&lt;\p&gt; - until the closing tag
$ - anchored to the end of the line

huangapple
  • 本文由 发表于 2023年2月9日 01:06:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定