--- type: "fhirpath-function" title: "FHIRPath Function: matches" function: "matches" category: "String Manipulation" section: "5.6.10" source: "fhirpath/functions.json" --- # FHIRPath Function: matches Returns `true` when the value matches the given regular expression. Regular expressions should function consistently, regardless of any culture- and locale-specific settings in the environment, should be case-sensitive, use 'single line' mode and allow Unicode characters. The start/end of line markers `^`, `$` can be used to match the entire string. If the input collection or `regex` are empty, the result is empty (`{ }`). If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment. The optional `flags` parameter can be set to: {:.stu} * `i` to perform a case-insensitive search (otherwise is case-sensitive) * `m` - Matches the start and end of each line using ^ and $ (multi-line)
(not only begin/end of string) {:.stu} ``` fhirpath 'http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1'.matches('Library') // returns true 'N8000123123'.matches('^N[0-9]{8}$') // returns false as the string is not an 8 char number (it has 10) 'N8000123123'.matches('N[0-9]{8}') // returns true as the string has an 8 number sequence in it starting with `N` ``` ## Summary - **Category**: String Manipulation - **Section**: `5.6.10` - **Return Type**: `Boolean` - **Empty Input Result**: `empty` - **Errors on Multiple Input**: `true` ## Description Returns `true` when the value matches the given regular expression. Regular expressions should function consistently, regardless of any culture- and locale-specific settings in the environment. ## Arguments - `regex`: `String` - Regular expression to match against - `flags` (optional): `String` - Optional flags for the regex (i for case-insensitive, m for multi-line) ## Type Mapping - `String-Boolean` ## Example ```fhirpath 'http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1'.matches('Library') // returns true 'N8000123123'.matches('^N[0-9]{8}$') // returns false as the string is not an 8 char number (it has 10) ```