functx:contains-word
Whether one string contains another, as a separate word
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.
Parameters |
Description |
|---|---|
arg:string() |
the string to search |
word:string() |
the word to find |
Examples
XPath |
Results |
Explanation |
|---|---|---|
functx:contains-word('abc def ghi', 'def') |
true |
def is separated by spaces. |
functx:contains-word('abc.def\ghi', 'def') |
true |
Any non-word character separates words, such as . and \. |
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. |
In a generator
Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-functx-contains-word.
[e] example-functx-contains-word
[e] start
[e] match
[v] /
[e] body
[e] write-pattern
[v] examples
[e] patterns
[e] examples
[v] E01: {{ functx:contains-word('abc def ghi', 'def') }}
[v] E02: {{ functx:contains-word('abc.def\ghi', 'def') }}
[v] E03: {{ functx:contains-word('abc def ghi', 'abc') }}
[v] E04: {{ functx:contains-word('abc', 'abc') }}
[v] E05: {{ functx:contains-word('abcdef', 'abc') }}