fn:matches

Matches a string with a pattern.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

fn:matches(string $string, string $pattern) => boolean
fn:matches(string $string, string $pattern, string $flags) => boolean

Description

The function returns true if $string matches the regular expression supplied as $pattern as influenced by the value of $flags, if present; otherwise, it returns false. This function provides patternmatching functionality which might prove useful for users familiar with this concept. For searching in large data sets, however, it is recommended to rather use Tamino's own text retrieval facilities for better performance.

Argument

$sequence

a string to be matched

$pattern

a pattern

$flags

modifiers for patternmatching

Example

  • For each author return the name and a boolean indicating whether it ends with an 'l'. $ is an anchor character denoting the end of a string.

    for $author in distinct-values(input()//author/last)
    return 
    <author>
    <name>{$author}</name>
    <match>{matches($author,'l$')}</match>
    </author>

    The query returns the four different authors wherein Abiteboul is marked with true. If the pattern is changed to 'l $' Abiteboul does no longer match. It matches again when using the flag string 'x' as third parameter, since then whitespace characters in the regular expression are removed prior to matching.