【问题标题】:Apply regex on marked lines in Notepad++在记事本++中的标记行上应用正则表达式
【发布时间】:2017-11-23 12:39:10
【问题描述】:

我在 xsl 文件中有数千个这样的 xsl 模板。

<xsl:template name="foo">
...
...
</xsl:template>
<xsl:template match="bar" > <!-- ending spaces after quote -->
...
...
</xsl:template>

我的工作是在这里添加相同的命名空间。 更改后的 xsl 看起来像

    <xsl:template name="foo" xmlns="http://example.org">
    ...
    ...
    </xsl:template>
    <xsl:template match="bar" xmlns="http://example.org" > 
    ...
    ...
    </xsl:template>

这是我的方法

1.标记所有以&lt;xsl:template开头的行

2.在标记的行上添加正则表达式。

我坚持第 2 点。我怎样才能只在标记的行上应用一些正则表达式?

你有什么更好的办法吗?

更新

我的挑战是仅在标记线上将所有&gt; 替换为xmlns="http://example.org"&gt;

【问题讨论】:

  • 为什么不将&lt;xsl:template name="foo"&gt;替换为纯文本:&lt;xsl:template name="foo" xmlns="http://example.org"&gt;
  • 如果我有一个foo 来改变那会是明智的吗?我还需要处理Bar。还有很多..
  • 好的,现在任务很明确了。 问题是什么?
  • @WiktorStribiżew 这个问题解决了我认为的任务

标签: regex notepad++


【解决方案1】:

您不需要标记线。搜索整个值,然后在需要的适当位置替换。像这样:

在这里我们试图找到这个: &lt;xsl:template name="foo" 并替换为: \1\2\3(\ )xmlns="http://example.org"

【讨论】:

  • 它就像一个魅力。但是用正则表达式替换 \1\2\3 xmlns="http://example.org" 不确定为什么需要 () ?
  • (\ ) 是为了添加空间。如果\1\2\3 xmlns="http://example.org" 工作正常,那么没关系。
  • 最后一个可爱的正则表达式将用\1 xmlns="http://example.org"替换(&lt;xsl:template name=.*")
猜你喜欢
  • 2016-04-05
  • 2018-11-17
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 2014-05-03
  • 1970-01-01
相关资源
最近更新 更多