Table Of Contents

Match Pattern (G Dataflow)

Last Modified: January 9, 2017

Searches for a pattern of characters within a string as specified by a limited set of regular expressions. If this node finds a match, it splits the input string into three substrings: the string that appears before the match, the match itself, and the string that appears after the match.

Match Pattern gives you fewer options for matching strings but performs more quickly than Match Regular Expression. For example, Match Pattern does not support the parenthesis or vertical bar (|) characters.

connector_pane_image
datatype_icon

string

The input string to search.

datatype_icon

regular expression

The pattern for which you want to search in string. regular expression is limited to the following regular expression characters: . (period), *, +, ?, [], ^, $, \, \b, \f, \n, \s, \r, \t, and \xx. Furthermore, this input does not support character grouping, alternate pattern matching, backreferences, or non-greedy quantification.

For more complex pattern matching, use Match Regular Expression.

Definitions of Special Characters

Special Character Description Example(s)
. (period) Matches any single character except a newline character. Within square brackets, . is literal.

Input String: Welcome to LabVIEW.

Regular Expression: t....

Match: to La

If you input [z.] as the regular expression, the period is literal and matches either . or z. In this example, [z.] returns . as the match.

* Marks the single preceding character or character class as one that can appear zero or more times in the input. Because an asterisk can match a pattern that appears zero times, regular expressions that include an asterisk can return an empty string if the whole pattern is marked with an asterisk. This quantifier matches as many characters as possible.

Input String: Hello LabVIEW!

Regular Expression: el*

Match: ell

Expressions such as w* or (welcome)* match an empty string if the node finds no other matches.

+ Marks the single preceding character or character class as one that can appear one or more times in the input. This quantifier matches as many characters as possible.

Input String: Hello LabVIEW!

Regular Expression: el+

Match: ell

? Marks the single preceding character or character class as one that can appear zero or one time in the input. This quantifier matches as many characters as possible by default.

Input String: Hello LabVIEW!

Regular Expression: el?

Match: el

[] Creates a character class, which allows you to match any one of a set of characters that you specify. For example, [abc] matches a, b, or c. Match Pattern interprets special characters inside square brackets literally, with the following exceptions:
  • - (dash)—Indicates a range when used between digits, or lowercase or uppercase letters; for example, [0-5], [a-g], or [L-Q].
  • ~—Matches any character, including non-displayable characters, except for the characters or range of characters in brackets. For example, [~0-9] matches any character other than 0 through 9.
  • ^—Matches any displayable character, including the space character, except the characters or range of characters enclosed in the brackets. For example, [^0-9] matches all displayable characters, including the space character, except 0 through 9.

Input String: version=14.0.1

Regular Expression: [0-9]+\.[0-9]+\.[0-9]+

Match: 14.0.1

The expression [0-9] matches any digit. The plus sign matches the previous character class, [0-9], one or more times but as many times as possible. The expression \. matches a literal . character. The plus sign matches the previous character class, [0-9], one or more times but matches as many times as possible. You can use this regular expression to match a three-part version number.

^ If ^ is the first character of regular expression, it anchors the match to the offset in string. The match fails unless regular expression matches that portion of string that begins with the character at offset. If ^ is not the first character in the regular expression, it is treated as a regular character.

Input String: Hello LabVIEW!

Regular Expression: ^[^ ]+

Match: Hello

From the beginning of the input string, this regular expression matches as many characters – other than a space character – as possible. You can use this regular expression to isolate the first word, numeral, or other character combination of a string.

$ If $ is the last character of regular expression, it anchors the match to the last element of string. The match fails unless regular expression matches up to and including the last character in the string. If $ is not the last character in the regular expression, it is treated as a regular character.

Input String: Hello LabVIEW!

Regular Expression: [^ ]+$

Match: LabVIEW!

From the end of the input string, this regular expression matches as many characters – other than a space character – as possible. You can use this regular expression to isolate the last word, numeral, or other character combination of a string.

\ Cancels the interpretation of any special character in this list. For example, \? matches a question mark, \. matches a period, and \\ matches a backslash. You also can use the following constructions for the following non-displayable characters:
  • \b—Backspace
  • \f—Form feed
  • \n—New line
  • \s—Space
  • \r—Carriage return
  • \t—Tab
  • \xx—Any character, where xx is the hex code using 0 through 9 and upper case A through F.
Input String:
Welcome
to   the LabVIEW Help!

Regular Expression: come\nto\tthe\sLabVIEW\sHelp\21

Match:
come
to   the LabVIEW Help!

The expression come\n matches the literal letters followed by a newline character. The expression to\t matches the literal characters to followed by a tab. The two \s expressions match the spaces between the and LabVIEW and LabVIEW and Help!. The expression \21 matches the exclamation point because 21 is the hexadecimal code for an exclamation point.

spd-note-note
Note  

If you want to include special characters in the search string, you must enclose each special character in brackets. For example, to search for the string hz+, enter hz[+] in regular expression. Otherwise, the node uses the special character to refine the search.

What Happens When There Is No Match?

If the node does not find regular expression, match substring is empty, before substring is the entire string, after substring is empty, and offset past match is -1. Match Pattern is compatible with a limited set of regular expressions and does not support character grouping, alternate pattern matching, backreferences, or non-greedy quantification. You can use a specific set of special characters to refine the search.

Examples of Allowable Regular Expressions

Characters to Find Regular Expression
All uppercase and lowercase versions of volts, that is, VOLTS, Volts, volts, and so on [Vv][Oo][Ll][Tt][Ss]
A plus sign or a minus sign [+-]
A sequence of one or more digits [0-9]+
Zero or more spaces \s* or * (that is, a space followed by an asterisk)
One or more spaces, tabs, new lines, or carriage returns [\t\r\n\s]+
The word Level only if it appears at the offset position in the string Level$
The longest string within parentheses (.*)
The longest string within parentheses, but not containing any parentheses within it ([~()]*)
A left bracket \[
A right bracket \]
cat, dog, cot, dot, cog [cd][ao][tg]
datatype_icon

offset

The number of bytes into the input string at which this node begins its operation.

The offset of the first byte in the input string is 0. If offset is beyond the end of the input string, this node returns an empty string.

spd-note-note
Note  

Strings are encoded in UTF-8. In most cases, the number of bytes in a string is equivalent to the number of characters. However, for strings containing the characters U+0080 through U+7FFFFFFF, the number of bytes is greater than the number of characters.

Default: 0

datatype_icon

before substring

A string containing all the characters in string that occur before the match.

datatype_icon

match substring

First string after offset that matches the pattern specified by regular expression.

datatype_icon

after substring

A string containing all characters in string that follow the match.

datatype_icon

offset past match

The index in string of the first byte of after substring. If the node does not find a match, offset past match is -1.

spd-note-note
Note  

Strings are encoded in UTF-8. In most cases, the number of bytes in a string is equivalent to the number of characters. However, for strings containing the characters U+0080 through U+7FFFFFFF, the number of bytes is greater than the number of characters.

string regular expression offset match offset past match Comments
cdb b* 0 "" 0 The offset input and the offset past match output might be equal when the empty string is a valid match for the regular expression.
bbbcd b* 0 bbb 3 Notice that offset does not equal offset past match because a longer match than the empty string existed.

Where This Node Can Run:

Desktop OS: Windows

FPGA: All devices (only within an Optimized FPGA VI)


Recently Viewed Topics