<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Extract Function</title><link>https://community.appian.com/discussions/f/general/28090/extract-function</link><description>Hi All I have requirement to get the values between square brackets iam achieving it with the help of extract function but when i was trying to insert the brackets after entering value and if my text value has uneven number of brackets it is erroring</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/115973?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2023 07:12:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a5fd9547-6e17-4dbd-b667-1c3db01f4d68</guid><dc:creator>Shanmathi Ponnusamy</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/tejashwinin0822"&gt;tejashwinin0822&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Can you please check if the below code works for your use case?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!values: split(ri!myString, &amp;quot;[&amp;quot;),
  local!valuesWithCloseBracket: reject(
    a!isNullOrEmpty,
    a!forEach(
      items: local!values,
      expression: if(search(&amp;quot;]&amp;quot;, fv!item) &amp;gt; 1, fv!item, null)
    )
  ),
  a!forEach(
    items: local!valuesWithCloseBracket,
    expression: split(fv!item, &amp;quot;]&amp;quot;)[1]
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/115972?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2023 06:48:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:73b34635-d940-48bf-8759-3fc5bf36b56a</guid><dc:creator>michelek1257</dc:creator><description>&lt;p&gt;Your work is truly appreciated around the clock and globally. It is a comprehensive and useful blog&amp;nbsp;&lt;a href="https://lol-beans.io"&gt;&lt;strong&gt;Lolbeans&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/115929?ContentTypeID=1</link><pubDate>Mon, 10 Jul 2023 14:20:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b7e25c54-efdf-42d2-abb0-5d40b2525182</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;nice try...&lt;br /&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1688998795671v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/115915?ContentTypeID=1</link><pubDate>Mon, 10 Jul 2023 11:45:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ff928f08-f3d9-4ad5-90e8-c66447d8153e</guid><dc:creator>flaughers9083</dc:creator><description>[deleted]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/115907?ContentTypeID=1</link><pubDate>Mon, 10 Jul 2023 10:03:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d60fed81-fd0e-4907-a2b5-3bc4cce523dc</guid><dc:creator>Vaithyanathan Raju</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/stewart.burchell"&gt;Stewart Burchell&lt;/a&gt; - Even if we have even number of &amp;quot;[" and "]&amp;quot; will it be only taking first combination of the same?&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;extract(
  &amp;quot;[This [is [the] Test] String]&amp;quot;,
  &amp;quot;[&amp;quot;,
  &amp;quot;]&amp;quot;
)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1688983341717v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109522?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 21:49:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d14c477a-30ec-48e1-9ddf-6a66333a7ddf</guid><dc:creator>Abhay Dalsaniya</dc:creator><description>&lt;p&gt;May be it make sense to the other person on how the exact() function works, because the the original post and subject&amp;nbsp; mentions about extract() function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109509?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 19:44:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:90d1cf94-55ee-4618-b7ad-b6a470e20726</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;not sure what the point of this is - this doesn&amp;#39;t have much to do with the error the user describes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109507?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 19:35:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a1d86790-cce8-456b-b8f9-3fb05f1f886c</guid><dc:creator>Abhay Dalsaniya</dc:creator><description>&lt;table class="table table-bordered fold dataTable no-footer" id="example" cellspacing="0" width="100%"&gt;
&lt;tbody&gt;
&lt;tr class="even"&gt;
&lt;td&gt;
&lt;p&gt;&lt;strong&gt;extract()&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Returns the value (or values, if the text contains multiple delimited values) between the delimiters from the given text.&lt;/p&gt;
&lt;/td&gt;
&lt;td class=""&gt;&lt;code class="highlight language-sail"&gt;&lt;span class="nf"&gt;extract&lt;/span&gt;&lt;span class="ow"&gt;(&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;name: Bob, name: Karen, name: Sam&amp;quot;&lt;/span&gt;&lt;span class="ow"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;:&amp;quot;&lt;/span&gt;&lt;span class="ow"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;,&amp;quot;&lt;/span&gt; &lt;span class="ow"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109502?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 18:47:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:15862404-b529-4efc-86d3-0c3b237f07a5</guid><dc:creator>tejashwinin0822</dc:creator><description>&lt;p&gt;a!localVariables(&lt;br /&gt; local!datacontent: fn!char(&lt;br /&gt; fn!code(ri!text)&lt;br /&gt; ),&lt;br /&gt; local!sum: a!forEach(&lt;br /&gt; items: local!datacontent,&lt;br /&gt; expression: a!match(&lt;br /&gt; value: fv!item,&lt;br /&gt; equals: &amp;quot;[",&lt;br /&gt; then: 1,&lt;br /&gt; equals: "]&amp;quot;,&lt;br /&gt; then: - 1,&lt;br /&gt; default: 0&lt;br /&gt; ),&lt;/p&gt;
&lt;p&gt;),&lt;br /&gt; local!totalSum: fn!sum(local!sum),&lt;br /&gt; local!statusCode: if(local!totalSum = 0, 1, 0),&lt;br /&gt; local!result: union(&lt;br /&gt; if(&lt;br /&gt; local!totalSum = 0,&lt;br /&gt; fn!extract(&lt;br /&gt; ri!text,&lt;br /&gt; &amp;quot;[",&lt;br /&gt; "]&amp;quot;&lt;br /&gt; ),&lt;br /&gt; &amp;quot;&amp;quot;&lt;br /&gt; ),&lt;br /&gt; touniformstring({})&lt;br /&gt; ),&lt;br /&gt; {&lt;br /&gt; if(&lt;br /&gt; local!statusCode = 1,&lt;br /&gt; &amp;quot;&amp;quot;,&lt;br /&gt; &amp;quot;Number of open square brackets and close square brackets must be equal&amp;quot;&lt;br /&gt; ),&lt;br /&gt; if(&lt;br /&gt; a!forEach(&lt;br /&gt; items: local!result,&lt;br /&gt; expression: find(&amp;quot;[&amp;quot;, fv!item)&lt;br /&gt; ),&lt;br /&gt; &amp;quot;No square brackets is allowed between [ and ]&amp;quot;,&lt;br /&gt; &amp;quot;&amp;quot;&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt;)&amp;nbsp; &amp;nbsp;in addition to your solution just added&amp;nbsp;&amp;nbsp;&lt;span&gt;find(&amp;quot;[&amp;quot;, fv!item) this to validation to prevent &amp;quot;[&amp;quot; in between open and close square brackets Thanks Stewart and Mike for you time and suggestion&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109487?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 16:25:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:448f56f7-3ef6-489c-a00f-376fd56862b1</guid><dc:creator>Mike Schmitt</dc:creator><description>[quote userid="3520" url="~/discussions/f/general/28090/extract-function/109484#109484"]Open to suggestions how to achieve a true parser here...?[/quote]
&lt;p&gt;It&amp;#39;s hard to say, really - there are too many unanswered questions about what the source data might be, and those things are required in order to form the initial assumptions behind a robust parser.&amp;nbsp; Without wasting the time actually trying, i&amp;#39;d guess it might be easier to make an exact one using regEx matching, though checking for potentially unlimited repeats can get pretty frustrating there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109484?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 16:07:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b6d560b1-7617-48f9-a1e1-6735069f06de</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Yeah, I&amp;#39;m not convinced...a true parser would&amp;nbsp;ensure that every opening &amp;quot;[" had a corresponding "]&amp;quot;. The &amp;quot;parser&amp;quot; above just ensures there&amp;#39;s an even number, which isn&amp;#39;t the same. Open to suggestions how to achieve a true parser here...?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109483?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 16:00:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ca559eca-fdc9-47ac-8704-4df53f0d9917</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;That&amp;#39;s a neat little parser.&amp;nbsp; I would have probably just resorted to splitting the original string on &amp;quot;[", then checking the members of the resulting array for the presence of "]&amp;quot; (i.e. each having at least 1 and only 1), and handling from there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109482?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 16:00:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3ef2ba88-0517-4297-818b-0b34f62ab899</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;There isn&amp;#39;t. So you have to get creative. See above responses.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109480?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:56:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5ec41b29-30bf-42c8-b10f-a83f7a2470db</guid><dc:creator>tejashwinin0822</dc:creator><description>&lt;p&gt;i went through all the functions but couldnt find the exact function to count number of&amp;quot;[&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109479?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:55:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5d01c61e-4d21-427d-8d86-c76e9b4e1a58</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;yeah, you&amp;#39;re right - i realized right after.&lt;/p&gt;
&lt;p&gt;so i guess we have to resort to a simple workaround like &lt;em&gt;&lt;strong&gt;len(&lt;a href="https://docs.appian.com/suite/help/23.1/fnc_text_cleanwith.html"&gt;cleanwith&lt;/a&gt;(local!myString, &amp;quot;[&amp;quot;))&lt;/strong&gt;&lt;/em&gt; - which will extract only that character from the original string then return the length of the result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109478?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:54:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5514556c-2dc6-42c3-a15e-d21a39424d96</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Um...find() only returns the first instance. Frustratingly (since it&amp;#39;s such a common use case) there&amp;#39;s no function that I&amp;#39;m aware of to count the instances of a string within a string, hence the heavyweight example I&amp;#39;ve provided.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109477?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:51:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d2f75b33-6bc5-4f9b-af41-57dbdbab4805</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Not directly, no. You have to break up the string into an array containing its individual characters and then you can count. Here&amp;#39;s something that I played with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!stringAsArray: fn!char(fn!code(ri!myString)),
  local!scoring: a!forEach(
    items: local!stringAsArray,
    expression: a!match(
      value: fv!item,
      equals: &amp;quot;[&amp;quot;,
      then: 1,
      equals: &amp;quot;]&amp;quot;,
      then: - 1,
      default: 0
    )
  ),
  local!scoreSum: fn!sum(local!scoring),
  local!statusCode: if(local!scoreSum = 0, 1, 0),
  local!result: if(
    local!scoreSum = 0,
    fn!extract(ri!myString, &amp;quot;[&amp;quot;, &amp;quot;]&amp;quot;),
    &amp;quot;INPUT ERROR&amp;quot;
  ),
  a!map(
    statusCode: local!statusCode,
    result: local!result
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Explanation:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;fn!char(fn!code(ri!myString)) generates the array of individual characters as described&lt;/li&gt;
&lt;li&gt;the a!forEach() then assigns a score for each character&lt;/li&gt;
&lt;li&gt;we then sum the individual scores - if there are an even number of &amp;quot;[" and "]&amp;quot; the score will be zero&lt;/li&gt;
&lt;li&gt;we then return an a!map() with the result. This contains a statusCode to indicate if the original string was valid or not, and a result&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Hope this makes sense&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109476?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:51:35 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e64b5cbf-c988-4679-ae30-099adff11507</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;you&amp;#39;ll want to check out standard appian expression functions &lt;s&gt;like &amp;quot;find()&amp;quot;&lt;/s&gt; to help with that.&lt;/p&gt;
&lt;p&gt;edit: find() doesn&amp;#39;t actually work for this (grumble) but i believe my example below will.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109474?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:46:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:eaf68e78-e342-4d1e-b7d0-bf3b4ef58254</guid><dc:creator>tejashwinin0822</dc:creator><description>&lt;p&gt;will definetly try this Thank you for the quick response&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109473?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:45:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ab36ccb8-09dc-4808-ab16-17cd5f845723</guid><dc:creator>tejashwinin0822</dc:creator><description>&lt;p&gt;Is there any function to count the number of &amp;quot;[&amp;quot;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109472?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:35:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3670dcba-d3f6-4385-93d8-d407f22a215e</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;...of course if you treat &amp;quot;[" and "]&amp;quot; as just pure delimiters then you can do something like this, which isn&amp;#39;t sensitive to the need for each &amp;quot;[" to have a matching "]&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;fn!reject(
  a!isNullOrEmpty,
  a!flatten(
    a!forEach(
      items: split(ri!myString, &amp;quot;[&amp;quot;),
      expression: split(fv!item, &amp;quot;]&amp;quot;)
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Extract Function</title><link>https://community.appian.com/thread/109469?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 15:17:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:198ee00e-cf84-4e97-8321-a8be43e11a0d</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;I would encourage you to validate the incoming string before you attempt to use the extract() function on it. There are probably a few ways to do this but in essence if you check that the string you want to process contains an even number of &amp;quot;[" and "]&amp;quot; characters then you&amp;#39;ll avoid the error. What might be a bit harder to achieve is to ensure that every &amp;quot;[" has a following "]&amp;quot; without another intervening &amp;quot;[&amp;quot;...if that even matters to you? But the principle here: don&amp;#39;t attempt to process data that is effectively invalid.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>