首页 > 解决方案 > 选择所有以一个字符开头的行并只保留一个条目

问题描述

我正在使用一个名为“rikaisama”的firefox插件,这个插件是一个弹出式日语词典,它允许使用epwing词典文件。在插件选项中,我们可以使用一个正则表达式来删除字典条目中不必要的部分。

我正在使用“Kenkyusha 的新日英词典”epwing 文件,但它有太多示例无法阅读。

条目示例:

まにあう【間に合う】 ローマ(maniau)
1 〔時間に遅れない〕 be in time 《for…》.
▲7 時の列車に間に合う catch [make] the 7 o'clock train
・締め切りに間に合う meet the deadline
・開演に間に合う arrive before curtain time
▲9 時の札幌行きに間に合うように空港に着いた. I arrived in time for the nine o'clock flight to Sapporo.
・「間に合うかな」「走っても間に合いそうにないね」 "Will we be in time?"―"It doesn't look like we'll be in time even if we run."
2 〔役に立つ〕 answer [serve, suit, meet] the purpose; be useful; be serviceable; be of use [service]; be good enough; 〔十分である〕 be enough; 〔用意ができる〕 be ready; 〔必要をみたす〕 meet the requirements; serve the [one's] turn [need].
▲「費用はどのぐらいかな」「5 万もあれば間に合うよ」 "And what is the expense?"―"Fifty-thousand yen should cover it."
・これだけあれば丸 1 年は間に合う. This will last us [see us through] one whole year. | This will be enough for a whole year.

其中以“▲”或“・”开头的所有条目都是示例,与此正则表达式匹配的所有条目都是定义:

\n[″*〖〈《⇒=➡【〔(〜A-Za-z0-9].*

我已经设法自己提出了这个正则表达式,但它删除了所有示例:

\n[^″*〖〈《⇒=➡【〔(〜A-Za-z0-9].*

是否有可能有一个匹配这个正则表达式的正则表达式和匹配的以下行?

希望的结果:

まにあう【間に合う】 ローマ(maniau)
1 〔時間に遅れない〕 be in time 《for…》.
▲7 時の列車に間に合う catch [make] the 7 o'clock train
2 〔役に立つ〕 answer [serve, suit, meet] the purpose; be useful; be serviceable; be of use [service]; be good enough; 〔十分である〕 be enough; 〔用意ができる〕 be ready; 〔必要をみたす〕 meet the requirements; serve the [one's] turn [need].
▲「費用はどのぐらいかな」「5 万もあれば間に合うよ」 "And what is the expense?"―"Fifty-thousand yen should cover it."

任何帮助表示赞赏!

标签: regex

解决方案


我想你几乎拥有它 - 只需添加\n.*它就可以了/\n[″*〖〈《⇒=➡【〔(〜A-Za-z0-9].*\n.*/。这使得它得到下一行......

在此处查看实际操作:https ://regexr.com/442st


推荐阅读