Regular Expression '
mit ''
zu ersetzen, wenn es in <xsl:
sonst '
sollte bleiben, wie es ist.
Code Snippet:
Regex Apostroph mit Apostroph zweimal zu ersetzen, wenn es innerhalb von <xsl: oder <XSL:
public static void main(String[] args) {
String replaceSingleQuoteInsideXsltCondition = "(<\\s*?xsl\\s*?:.*?=.*?)(')(.*?)(')(.*?>)";
String dummyXSLT = "<p>Thank you for sending us <xsl:for-each select=\"catalog/cd[artist='Bob Dylan']\"> " +
"paper's to prove your <span class=\"highlight\"><xsl:if test=\"D01 ='Y'\">Income</xsl:if></span> <span class=\"highlight\"><xsl:if test=\"D02 ='Y'\"> and " +
"</xsl:if></span><span class=\"highlight\"><xsl:if test=\"D03 ='Y'\">Citizenship and/or Identity</xsl:if></span>. " +
"We need a little more information to finish your application. Addition of few words like 7 o'clock, employees' or employ's and child's and 'xyz and 'hello'</p>" +
"contact number for inquiry = '478965152' and email id = '[email protected]'" +
"<xsl:template match=\"num[ . = 3 or . = 5]\"/></xsl:stylesheet><xsl:if test=\"contains($search, 'Web Developer') and (contains($expSearch, 'Computer') or contains($expSearch, 'Information') or contains($expSearch, 'Web'))\">" +
"<xsl:if test=\"((node/ABC!='') and (normalize-space(node/DEF)='') and (normalize-space(node/GHI)=''))\"> just a dummy sample.</xsl:if>";
System.out.println(dummyXSLT.replaceAll(replaceSingleQuoteInsideXsltCondition, "$1''$3''$5"));
}
Tatsächliches Ergebnis von oben Code:
<p>Thank you for sending us <xsl:for-each select="catalog/cd[artist=''Bob Dylan'']"> paper's to prove your <span class="highlight"><xsl:if test="D01 =''Y''">Income</xsl:if></span> <span class="highlight"><xsl:if test="D02 =''Y''"> and </xsl:if></span><span class="highlight"><xsl:if test="D03 =''Y''">Citizenship and/or Identity</xsl:if></span>. We need a little more information to finish your application. Addition of few words like 7 o'clock, employees' or employ's and child's and 'xyz and 'hello'</p>contact number for inquiry = '478965152' and email id = '[email protected]'<xsl:template match="num[ . = 3 or . = 5]"/></xsl:stylesheet><xsl:if test="contains($search, ''Web Developer'') and (contains($expSearch, 'Computer') or contains($expSearch, 'Information') or contains($expSearch, 'Web'))"><xsl:if test="((node/ABC!='''') and (normalize-space(node/DEF)='') and (normalize-space(node/GHI)=''))"> just a dummy sample.</xsl:if>
Erwartetes Ergebnis:
<p>Thank you for sending us <xsl:for-each select="catalog/cd[artist=''Bob Dylan'']"> paper's to prove your <span class="highlight"><xsl:if test="D01 =''Y''">Income</xsl:if></span> <span class="highlight"><xsl:if test="D02 =''Y''"> and </xsl:if></span><span class="highlight"><xsl:if test="D03 =''Y''">Citizenship and/or Identity</xsl:if></span>. We need a little more information to finish your application. Addition of few words like 7 o'clock, employees' or employ's and child's and 'xyz and 'hello'</p>contact number for inquiry = '478965152' and email id = '[email protected]'<xsl:template match="num[ . = 3 or . = 5]"/></xsl:stylesheet><xsl:if test="contains($search, ''Web Developer'') and (contains($expSearch, ''Computer'') or contains($expSearch, ''Information'') or contains($expSearch, ''Web''))"><xsl:if test="((node/ABC!='''') and (normalize-space(node/DEF)='''') and (normalize-space(node/GHI)=''''))"> just a dummy sample.</xsl:if>
Für etwas Regex verwandt, das so einfach ist, müssen Sie keine These als Beispiel veröffentlichen. Zeigen Sie vor und nach dem gewünschten String, dem verwendeten Regex und den Strings, die Ihnen Probleme bereiten.Es ist immer besser, zunächst eine Regex zu erstellen, die alles tut, was Sie brauchen. Weil Sie das als Referenz verwenden müssen, wenn Sie versuchen, die Regex in Teile zu zerlegen, was den gesamten Umfang verändert. – sln
@Sanjay könnten Sie ein Ein-Wort-Beispiel vielleicht hinzufügen (zB 'computer' vs' '' computer''' oder etwas? –
Ich habe hinzugefügt Abschnitt, um das Problem in einfachen Begriff zu erarbeiten. –