简体   繁体   English

用正则表达式替换两个引号应该是什么?

[英]What should be regular expression to replace only two quotes?

<element>
  <Argument Name="AWSAccessKeyId" Value="APOEIUVWIE8E78E6"></Argument>
  <Argument Name="SearchIndex" Value="Apparel"></Argument>
  <LegalDisclaimer>Leriya Fashion products,on amazon.in."Leriya Fashion" in search.</LegalDisclaimer>
</element>

I want to replace only quotes in this word ("Leriya Fashion").I have tried many regular expression but they replace all the quotes.Right now we know this word but what if we don't know the actual word. 我只想替换该词(“ Leriya Fashion”)中的引号。我尝试了许多正则表达式,但它们替换了所有引号。现在我们知道这个词,但是如果我们不知道实际的词怎么办。

  1. "|[az]$$|"$
  2. "|"+\\s

I want to replace it with blank or space. 我想用空白或空格代替它。 And the main problem is occurred when we convert this xml to json. 当我们将此xml转换为json时,就会发生主要问题。 Because json take this double quoted as value but in actual its not a value its just a name which is double quoted.So for me its very tough to replace this quote with blank in json thats why I'm trying to replace this in xml file. 因为json将此双引号作为值,但实际上它不是一个值,它只是一个双引号的名称。所以对我来说,很难用json中的空白替换此引号,这就是为什么我要在xml文件中替换它。

If it's only "Leriya Fashion" , then why not just use String::replace 如果只是"Leriya Fashion" ,那为什么不只使用String::replace

str = str.replace("\"Leriya Fashion\"", "Leriya Fashion");

I'm assuming you just want to remove the quotes. 我假设您只是想删除引号。

Lambda replaceAll Lambda replaceAll

str = Pattern.compile("(.)\"([^\"\r\n]*\"").matcher(str)
    .replaceAll(mr -> mr.group(1).equals("=") ? mr.group()
                      : mr.group(1) + mr.group(2));

This will replace all quotes from any text "..." from non-HTML-attributes ( ="..." ). 这将替换非HTML属性( ="..." )中任何文本 "..."所有引号。 The dangerous assumption is that quotes only appear in pairs. 危险的假设是引号只能成对出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM