Description
The functx:contains-word function returns true if $word is contained in $arg as a separate word. It must be delimited by non-word characters or the beginning or end of $arg. It is case insensitive; it matches a word even if the case is different.
A "non-word character" is one that in Unicode belongs in either the Punctuation, Separators or Other category. Generally, most punctuation and white space are considered non-word characters, while letters and digits are word characters.
Arguments and Return Type| Name | Type | Description |
$arg |
xs:string? |
the string to search |
$word |
xs:string |
the word to find |
| return value |
xs:boolean |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:contains-word
( $arg as xs:string? ,
$word as xs:string ) as xs:boolean {
matches(upper-case($arg),
concat('^(.*\W)?',
upper-case(functx:escape-for-regex($word)),
'(\W.*)?$'))
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function contains-word
( $arg as xs:string? ,
$word as xs:string ) as xs:boolean {
fn:matches(fn:upper-case($arg),
fn:concat('^(.*\W)?',
fn:upper-case(functx:escape-for-regex($word)),
'(\W.*)?$'))
} |
Examples| XQuery Example | Results | Explanation |
|---|
functx:contains-word('abc def ghi', 'def')
|
true
|
functx:contains-word('abc.def\ghi', 'def')
|
true
|
functx:contains-word('abc def ghi', 'abc')
|
true
|
It can be at the beginning or end. |
functx:contains-word('abc', 'abc')
|
true
|
It can be the whole value. |
functx:contains-word('abcdef', 'abc')
|
false
|
abc does not appear as a separate word. |
Depends OnSee AlsoHistory |
|