Table Of Contents

Match Pattern (G Dataflow)

Version:
    Last Modified: March 2, 2017

    Searches for a pattern of characters in 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.

    This node performs more quickly than Match Regular Expression but gives you fewer options for matching strings. 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 the input string. This input 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.

    Definitions of Special Characters

    Special Character Description Examples
    . (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 use [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 mark a pattern as one 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 applies to 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 applies to 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 applies to as many characters as possible.

    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. This node 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 the specified search string, it anchors the match to the offset in string. The match fails unless the specified search string 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 the specified search string, it anchors the match to the last element of string. The match fails unless the specified search string 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 the specified search string. Otherwise, the node uses the special character to refine the search.

    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. For strings containing characters in the U+0000 through U+007F range, 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 the input string that occur before the match.

    datatype_icon

    match substring

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

    datatype_icon

    after substring

    String containing all characters in the input string that follow the match.

    datatype_icon

    offset past match

    The index in the input string of the first byte of after substring. If the node does not find a match, this output returns -1.

    spd-note-note
    Note  

    Strings are encoded in UTF-8. For strings containing characters in the U+0000 through U+007F range, 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.

    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.

    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: DAQExpress does not support FPGA devices


    Recently Viewed Topics