<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: ReplaceText Regex to replace double quotes in a string in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121018#M83781</link>
    <description>&lt;P&gt;You could split it into ExtractText with a dynamic property "json" as "(.*?&amp;lt;MyXML&amp;gt;)(.*?)(&amp;lt;\/MyXML&amp;gt;.*)"&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9771-extracttext.png" style="width: 582px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/22854iB5BA14EBC0F42601/image-size/medium?v=v2&amp;amp;px=400" role="button" title="9771-extracttext.png" alt="9771-extracttext.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and ReplaceText as follows: "${json.1}${json.2:replace('"', '\\"')}${json.3}" (i.e. with 4 backslashes)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9772-replacetext.png" style="width: 604px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/22855i069A4716C80FECC3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="9772-replacetext.png" alt="9772-replacetext.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This will create&lt;/P&gt;&lt;PRE&gt;[ { "XML": "&amp;lt;MyXML&amp;gt; This is a \"test\" XML &amp;lt;/MyXML&amp;gt;" } ]&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Aug 2019 10:30:42 GMT</pubDate>
    <dc:creator>bwalter1</dc:creator>
    <dc:date>2019-08-19T10:30:42Z</dc:date>
    <item>
      <title>ReplaceText Regex to replace double quotes in a string</title>
      <link>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121017#M83780</link>
      <description>&lt;P&gt;I am working with the ReplaceText processor to replace only some instances of a double quote character (") in a FlowFile and I am having difficulty with my Regex syntax. &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Background&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;I am pulling an XML column from our database using ExecuteSQL which converts the results to Avro format. I run this through an AvroToJson processor but the JSON produced does not correctly escape double quotes found in my DB columns. I am converting to JSON because my end goal is to have the XML values in a FlowFile, line by line. &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;:&lt;/P&gt;&lt;PRE&gt;[ { "XML": "&amp;lt;MyXML&amp;gt; This is a "test" XML &amp;lt;/MyXML&amp;gt;" } ]&lt;/PRE&gt;&lt;P&gt;As you can see the quotes surrounding "test" are invalid and need to be escaped to be:&lt;/P&gt;&lt;PRE&gt;[ { "XML": "&amp;lt;MyXML&amp;gt; This is a \"test\" XML &amp;lt;/MyXML&amp;gt;" } ]&lt;/PRE&gt;&lt;P&gt;I am trying to achieve this with the ReplaceText Processor. Using Regex I can correctly retrieve all the text between the &amp;lt;MyXML&amp;gt; tags but I am unable to single out the double quotes for replacement. &lt;/P&gt;&lt;P&gt;I have attempted to use back-references to replace the value in the middle capturing group, but that does not appear to work. Am I able to achieve this or do I need to be looking at an ExecuteScript processor and attempting it with Python/Groovy?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample processor config:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9760-screen-shot-2016-11-24-at-44503-pm.png" style="width: 793px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/22856iDC6D8571212FD04E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="9760-screen-shot-2016-11-24-at-44503-pm.png" alt="9760-screen-shot-2016-11-24-at-44503-pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 10:30:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121017#M83780</guid>
      <dc:creator>d_muldoon</dc:creator>
      <dc:date>2019-08-19T10:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: ReplaceText Regex to replace double quotes in a string</title>
      <link>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121018#M83781</link>
      <description>&lt;P&gt;You could split it into ExtractText with a dynamic property "json" as "(.*?&amp;lt;MyXML&amp;gt;)(.*?)(&amp;lt;\/MyXML&amp;gt;.*)"&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9771-extracttext.png" style="width: 582px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/22854iB5BA14EBC0F42601/image-size/medium?v=v2&amp;amp;px=400" role="button" title="9771-extracttext.png" alt="9771-extracttext.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and ReplaceText as follows: "${json.1}${json.2:replace('"', '\\"')}${json.3}" (i.e. with 4 backslashes)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9772-replacetext.png" style="width: 604px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/22855i069A4716C80FECC3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="9772-replacetext.png" alt="9772-replacetext.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This will create&lt;/P&gt;&lt;PRE&gt;[ { "XML": "&amp;lt;MyXML&amp;gt; This is a \"test\" XML &amp;lt;/MyXML&amp;gt;" } ]&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2019 10:30:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121018#M83781</guid>
      <dc:creator>bwalter1</dc:creator>
      <dc:date>2019-08-19T10:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: ReplaceText Regex to replace double quotes in a string</title>
      <link>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121019#M83782</link>
      <description>&lt;P&gt;Thank you! I was having difficulty with the replace function. I had not thought to first use the ExtractText processor. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 23:54:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/ReplaceText-Regex-to-replace-double-quotes-in-a-string/m-p/121019#M83782</guid>
      <dc:creator>d_muldoon</dc:creator>
      <dc:date>2016-11-28T23:54:48Z</dc:date>
    </item>
  </channel>
</rss>

