home contribute faq download

FunctX XSLT Functions

functx:substring-before-last-match

The substring after the first text that matches a regex

Google
Webdatypic.com

Description

The functx:substring-before-last-match function returns the part of $arg that appears before the last match of $regex. If $arg does not match $regex, the entire $arg is returned. If $arg is the empty sequence, the empty sequence is returned.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to substring
$regex xs:string the regular expression
return value xs:string?

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:substring-before-last-match" as="xs:string?"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="arg" as="xs:string?"/>
  <xsl:param name="regex" as="xs:string"/>

  <xsl:sequence select="
   replace($arg,concat('^(.*)',$regex,'.*'),'$1')
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:substring-before-last-match(
  'abc-def-ghi', '[ce]')
abc-d
functx:substring-before-last-match(
  'abcd-abcd', 'ab?')
abcd-
functx:substring-before-last-match(
  'abcd-abcd', 'x')
abcd-abcd

See Also

fn:substring-beforeThe substring before the first occurrence of a delimiter
functx:substring-before-matchThe substring before the last text that matches a regex
functx:substring-after-matchThe substring after the first text that matches a regex
functx:substring-after-last-matchThe substring after the last text that matches a regex

History

Published OnLast UpdatedContributor(s)
2007-08-112007-08-11Priscilla Walmsley, Datypic, pwalmsley@datypic.com, https://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery