<?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>File Extension</title><link>https://community.appian.com/discussions/f/rules/26332/file-extension</link><description>Hello Team, 
 I need to extract the file extension in a string StoneX - Dist. Agreement - XX Draft 12 Dec 2021.docx. 
 I cannot use the document function to extract the file extension since we have the option to delete/remove the file from repository</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: File Extension</title><link>https://community.appian.com/thread/103341?ContentTypeID=1</link><pubDate>Fri, 21 Oct 2022 22:24:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5c3d0515-fd99-4c3b-a3c0-db5356f721ac</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I just use a pair of helper expression rules to get the document name from the ID (as it returns a whole name in a plaintext blob of info, we need to extract it from the output)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!rawDetails: if(
    a!isNullOrEmpty(ri!doc),
    &amp;quot;&amp;quot;,
    getcontentobjectdetailsbyid(ri!doc)
  ),
  local!wholeName: index(extract(
    local!rawDetails,
    &amp;quot;[Name: &amp;quot;,
    &amp;quot;, UUID:&amp;quot;
  ), 1, null()),

  rule!UTIL_processDocumentName(
    docName: local!wholeName
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That in turn calls UTIL_processDocumentName (which can be fed a &amp;quot;whole filename&amp;quot; from any source and for any reason) and uses Regex to help prevent weird corner-cases:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!hasNoExtension: search(&amp;quot;.&amp;quot;, ri!docName) = 0,
  
  local!namePart: if(
    local!hasNoExtension,
    ri!docName,
    regexsearch(
      pattern: &amp;quot;.*(?=\.)&amp;quot;,
      searchString: ri!docName,
      regexFlags: &amp;quot;i&amp;quot;
    )[1].match
  ),
  
  local!extension: if(
    local!hasNoExtension,
    &amp;quot;&amp;quot;,
    regexsearch(
      pattern: &amp;quot;[^\.]*$&amp;quot;,
      searchString: ri!docName,
      regexFlags: &amp;quot;i&amp;quot;
    )[1].match
  ),
  
  a!map(
    name: local!namePart,
    extension: local!extension
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>