Description
The functx:replace-first function replaces, within $arg , the first area that matches $pattern ) with $replacement . If no area matches the pattern, no replacement is made.
Arguments and Return TypeName | Type | Description |
$arg |
xs:string? |
the entire string to change |
$pattern |
xs:string |
the pattern of characters to replace |
$replacement |
xs:string |
the replacement string |
return value |
xs:string |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:replace-first
( $arg as xs:string? ,
$pattern as xs:string ,
$replacement as xs:string ) as xs:string {
replace($arg, concat('(^.*?)', $pattern),
concat('$1',$replacement))
} ; |
ExamplesXQuery Example | Results |
---|
functx:replace-first('abcabcabc', 'ab', 'x') |
xcabcabc |
functx:replace-first('elementary', 'e.*e', 'x') |
xntary |
functx:replace-first(
'elementary', 'e.*?e', 'x') |
xmentary |
functx:replace-first('9999-9999', '\d+', 'X') |
X-9999 |
functx:replace-first('9999-9999', '\d{3}', 'X') |
X9-9999 |
See AlsoHistory |
Recommended Reading:
|