【问题标题】:notepad++ regex replace each occurence of a character only between two specific charactersnotepad++ 正则表达式仅在两个特定字符之间替换每个出现的字符
【发布时间】:2018-07-11 16:31:41
【问题描述】:

我只想替换文本中两个特定字符之间出现的每个字符。

例如,这里我想只在两个引号之间替换每次出现的空格或变音符号;也适用于多个链接:

1. Here is a <a href="#foö bar   foo bär">link</a> for foö bar and foo bär.
2. Here is a <a href="#foö bar   foo bär">link</a> for foö bar and foo bär.
3. Here is a <a href="#foö bar   foo bär">link</a> for foö bar and foo bär.

所以我想得到以下文字:

1. Here is a <a href="#fooe_bar_foo_baer">link</a> for foö bar and foo bär.
2. Here is a <a href="#fooe_bar_foo_baer">link</a> for foö bar and foo bär.
3. Here is a <a href="#fooe_bar_foo_baer">link</a> for foö bar and foo bär.

我正在考虑更换这样的东西:

(?<="[^"]*)\(s+?)(?=[^"]*")|(?<="[^"]*)(ä)(?=[^"]*")|...

与:

(?1_)(?2ae)...

但是后视中的量词不起作用。 提前谢谢...

【问题讨论】:

  • 编辑:本例中不止一个链接

标签: regex replace notepad++


【解决方案1】:
(\s+)(?![^"]*(?:"[^"]*")*[^"]*$)

您可以将它与前瞻一起使用。参见演示。

https://regex101.com/r/JLANJC/1

【讨论】:

  • 它不适用于本示例的多行。见regex101.com/r/JLANJC/2
  • 它也会替换每行引号外的空格。
  • @MichaSch 你能再检查一下吗
  • 能否请您再次帮助我如何让它工作:regex101.com/r/JLANJC/6
  • 这行得通:([^A-Za-zÄÖÜäöüß_#"]+)(?![^"]*(?:"[^"]*")*[^"]*$ )
【解决方案2】:

这应该可以解决问题

作为“搜索”:

"(.*)((ä)|(ö)|(ü)|(ß)|(\s))(.*)"

作为你的“替代品”

"\1(?2(?3ae)(?4oe)(?5ue)(?6sz)(?7_))\8"

编辑: 添加了缺失的变音符号

【讨论】:

  • 这只会替换最后出现的匹配字符。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-26
相关资源
最近更新 更多