Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何从捕获的通配符中删除空格?_Regex_Notepad++_Regex Group_Regex Greedy_Find Replace - Fatal编程技术网

Regex 如何从捕获的通配符中删除空格?

Regex 如何从捕获的通配符中删除空格?,regex,notepad++,regex-group,regex-greedy,find-replace,Regex,Notepad++,Regex Group,Regex Greedy,Find Replace,我正在尝试使用正则表达式在记事本++中使用Find&Replace来修改一些XML 这是我试图捕获的特定XML: <category name="Content Server Categories:FOLDER:test category"> <attribute name="test attribuut"><![CDATA[test]]></attribute> <attribute name="test attribuut

我正在尝试使用正则表达式在记事本++中使用Find&Replace来修改一些XML

这是我试图捕获的特定XML:

<category name="Content Server Categories:FOLDER:test category">
    <attribute name="test attribuut"><![CDATA[test]]></attribute>
    <attribute name="test attribuut1"><![CDATA[test1]]></attribute>
</category>

一种方法是分两步完成,因为之后会替换多个空格

获取所需的结构(注意使用非贪婪版本
*?
以防止过度匹配):

在替换中,将空格替换为捕获组1
$1

解释

  • (?:
    非捕获组

    • 如果总是正好有两个术语,只需匹配
      (\w+)(\w+)
      并删除空格。我认为您不能进行一般性替换。要么使用适当的脚本语言,要么进行两步替换,第二步删除
      之间的所有空格。并非总是精确的两个术语。这就是问题。
      @thefourthbirdone方法与multip要删除的le空格是首先使用获取所需的结构,然后使用替换空格。在我进行第一次替换后,下一个正则表达式将不匹配:(?:^我已经在记事本中使用我的示例中的内容对其进行了测试。您可以使用您的内容在regex101上创建一个示例吗?或者在不使用
      ^
      @michieldpaepe的情况下尝试它。我已经在记事本++中使用我的regex示例中的内容对其进行了测试。您可以在不使用类似于此的
      ^
      的情况下尝试吗?或者您可以与该内容共享一个regex101链接吗你在尝试哪一个呢?那一个几乎成功了!:)我的xml元素的结尾部分仍然不起作用..谢谢你的帮助,没有它是不可能成功的!
      <(category) name="Content Server Categories:(.+?)">(.+)</(category)>
      
      <category-FOLDER:testcategory name="Content Server Categories:FOLDER:test category">
          <attribute name="test attribuut"><![CDATA[test]]></attribute>
          <attribute name="test attribuut1"><![CDATA[test1]]></attribute>
      </category-FOLDER:testcategory>
      
      <($1-$2) name="Content Server Categories:($2)">($3)</($1-$2)>
      
      <category-FOLDER:test category name="Content Server Categories:FOLDER:test category">
          <attribute name="test attribuut"><![CDATA[test]]></attribute>
          <attribute name="test attribuut1"><![CDATA[test1]]></attribute>
      </category-FOLDER:test category>
      
      <category name="Content Server Categories:FOLDER:test category">
      
      <category name="Content Server Categories:FOLDER1:FOLDER2:test category">
      
      <category name="Content Server Categories:FOLDER NAME:test category">
      
      <category name="Content Server Categories:FOLDER NAME: FOLDER NAME1:test category">
      
      <category name="Content Server Categories:FOLDER:test category name">
      
      ...
      
      '. Matches newline' is __ON__
      
      <(category) name="Content Server Categories:(.+?)">(.+?)</(category)>
      
      <$1-$2 name="Content Server Categories:$2">$3</$1-$2>
      
      (?:</?category-|\G(?!^))\K\s*([\w:]+) (?!name=)