<?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>topic Re: Use regular expression to search and replace a string pattern in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714361#M33038</link>
    <description>&lt;P&gt;I share the thoughts of &lt;A href="https://answers.sap.com/users/5082/puneetdesai.html" target="_blank"&gt;Puneet&lt;/A&gt; : why make things tedious when a simple REPLACE can do the trick?&lt;/P&gt;&lt;P&gt;You could always got through the "&lt;A href="https://archive.sap.com/kmuuid2/1f9cd701-0b01-0010-87b8-f86f9b7b823f/Regex%20Toy-%20Testing%20Regular%20Expressions%20In%20ABAP.pdf" target="_blank"&gt;DEMO_REGEX_TOY&lt;/A&gt;" program and test some RegEx-expressions however ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Oct 2018 22:10:19 GMT</pubDate>
    <dc:creator>NTeunckens</dc:creator>
    <dc:date>2018-10-24T22:10:19Z</dc:date>
    <item>
      <title>Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714359#M33036</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I hope someone can help me.&lt;/P&gt;
  &lt;P&gt;I want to build a regular expression (using REPLACE ALL OCCURRENCES OF REGEX ...) to modify a string (pattern) in a big string. &lt;/P&gt;
  &lt;P&gt;I have a big string (json) where I have a lot of string patterns that look like this one:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;"custom_variables":{"product":"test","category":"washing_machine","sales_unit":"dach","ticket":"12345"},&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;PRE&gt;&lt;CODE&gt;"custom_variables":{"product":"test2","category":"washing_machine","sales_unit":"us","ticket":"9191191"},&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;They always start with &lt;STRONG&gt;"custom_variables":{&lt;/STRONG&gt; and end with &lt;STRONG&gt;}&lt;/STRONG&gt;. I need to modify all occurrences of this pattern to look like this (just need to add some square brackets):&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;"custom_variables":[{"product":"test","category":"washing_machine","sales_unit":"dach","ticket":"12345"}],&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Can anyone help me please building a working regular expression I can use?&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Best regards,&lt;/P&gt;
  &lt;P&gt;Christian&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 20:19:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714359#M33036</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-24T20:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714360#M33037</link>
      <description>&lt;P&gt;Hello Christian,&lt;/P&gt;&lt;P&gt;It seems that you will not require REGEX. Try code piece below&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Puneet Desai&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPLACE ALL OCCURRENCES OF '"custom_variables":{' IN source_str WITH '"custom_variables":[{'.
REPLACE ALL OCCURRENCES OF '},' IN source_str WITH '}],'.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 21:49:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714360#M33037</guid>
      <dc:creator>former_member199637</dc:creator>
      <dc:date>2018-10-24T21:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714361#M33038</link>
      <description>&lt;P&gt;I share the thoughts of &lt;A href="https://answers.sap.com/users/5082/puneetdesai.html" target="_blank"&gt;Puneet&lt;/A&gt; : why make things tedious when a simple REPLACE can do the trick?&lt;/P&gt;&lt;P&gt;You could always got through the "&lt;A href="https://archive.sap.com/kmuuid2/1f9cd701-0b01-0010-87b8-f86f9b7b823f/Regex%20Toy-%20Testing%20Regular%20Expressions%20In%20ABAP.pdf" target="_blank"&gt;DEMO_REGEX_TOY&lt;/A&gt;" program and test some RegEx-expressions however ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 22:10:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714361#M33038</guid>
      <dc:creator>NTeunckens</dc:creator>
      <dc:date>2018-10-24T22:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714362#M33039</link>
      <description>&lt;P&gt;i think it need to be replace 2 times:&lt;/P&gt;&lt;P&gt;first for the {:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(reg1) = '(\W+\w+\W+)(\{)'.&lt;BR /&gt;
REPLACE ALL OCCURRENCES OF REGEX reg1 IN str WITH '$1[{$`'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;second for the }:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(reg2) = '("\w+":"\w+"|"\w+":"\d+")(\})'.
REPLACE ALL OCCURRENCES OF REGEX reg2 IN str WITH '$1}]'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 04:35:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714362#M33039</guid>
      <dc:creator>DoanManhQuynh</dc:creator>
      <dc:date>2018-10-25T04:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714363#M33040</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;thank you very much for your help and the examples.&lt;/P&gt;&lt;P&gt;I think a simple REPLACE will not really work. The closing brackets "}" occur multiple times in my JSON string structure. But I need to add square brackets only if there is a starting string like '"custom_variables":{'.&lt;/P&gt;&lt;P&gt;Maybe this was not clear enough in my first post!&lt;/P&gt;&lt;P&gt;I give you an example. This is how my big string looks like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;...
"other_variable":{"val":"string"},
"custom_variables":{"product":"test2","category":"washing_machine","sales_unit":"us","ticket":"9191191"},
"other_variable2":{"val2":"string2"},
...

"custom_variables":{"product":"test2","category":"washing_machine","sales_unit":"us","ticket":"9191191"},&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I only need to add suqare brackets if there ist a starting structure with "custom_variables..." etc.. This may occur multiple times in my big string.&lt;BR /&gt;The result should look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;...
"other_variable":{"val":"string"},
"custom_variables":[{"product":"test2","category":"washing_machine","sales_unit":"us","ticket":"9191191"}],
"other_variable2":{"val2":"string2"},
...
"custom_variables":[{"product":"test2","category":"washing_machine","sales_unit":"us","ticket":"9191191"}],&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I think I need a regular expression for this!? Right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Christian&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 06:39:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714363#M33040</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-25T06:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714364#M33041</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can anyone help me please?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Christian&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 06:31:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714364#M33041</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-26T06:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714365#M33042</link>
      <description>&lt;P&gt;so we need to know the difference between custom_variable and other_variable. if you already know what variable need to be replaced then you dont need REGEX function, just replace it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 06:43:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714365#M33042</guid>
      <dc:creator>DoanManhQuynh</dc:creator>
      <dc:date>2018-10-26T06:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714366#M33043</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;quynh.doanmanh&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;all I need is a regular expression, that is doing the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Find all appearances of the following string pattern: "custom_variables":{" and replace it by "custom_variables":[{"&lt;/LI&gt;&lt;LI&gt;Search for next, following } character and change it to }]&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I cannot do this with a simple REPLACE.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Christian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 13:38:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714366#M33043</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-26T13:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714367#M33044</link>
      <description>the regex i gave you did what you want but incase you want it to distinguish between custom_variable and other_variable then i think it a bit difficult because they all character with same format. this is just your sample so the regex may not exactly, you have to check it by yourself and there is also have a good F1 document on REGEX statement.&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 00:06:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714367#M33044</guid>
      <dc:creator>DoanManhQuynh</dc:creator>
      <dc:date>2018-10-29T00:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use regular expression to search and replace a string pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714368#M33045</link>
      <description>&lt;P&gt;I think you might have to do the steps exactly as you stated possibly in a loop at use the FIND statement to find the offset of your Customs_variabels part and its corresponding closing } and use string expressions to get your wanted results. &lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 07:14:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/use-regular-expression-to-search-and-replace-a-string-pattern/m-p/714368#M33045</guid>
      <dc:creator>ArthurParisius</dc:creator>
      <dc:date>2018-10-29T07:14:09Z</dc:date>
    </item>
  </channel>
</rss>

