Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Special Characters for Match Regular Expression

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

Use these special characters in the regular expression input of the Match Regular Expression and Search and Replace String functions. Right-click the Search and Replace String function and select Regular Expression from the shortcut menu to configure the function for advanced regular expression searches and partial match substitution in the replacement string. Resize the Match Regular Expression function to view any partial matches found in the string. You can use the Match Pattern function or the Match Regular Expression function to search strings for regular expressions. The Match Regular Expression function gives you more options for matching strings but performs more slowly than the Match Pattern function.

Note Note  The Match Regular Expression function does not support null characters in strings.

The regular expression syntax that the Match Regular Expression and the Search and Replace String functions accept is provided by the PCRE library package, which is written by Philip Hazel and copyright by the University of Cambridge, England. LabVIEW incorporates this software.

Special CharacterInterpreted As
. Matches any single character except a newline character. For example, .t matches at, bt, 2t, _t, and so on.
*Marks part of a pattern as one that can appear zero or more times in the input. For example, be* marks e as a pattern that can appear 0 or more times. Therefore, be* matches be in believe, bee in beep, and b in bat. In the last example, the e* did not match a character, but the whole match still succeeded. This can be a problem if the whole pattern is marked with an asterisk. For example, if you enter the pattern b*, an empty string and the input abbc return a successful match.
+Marks part of a pattern as one that can appear one or more times in the input. For example, be+ matches be in believe, bee in beep, and fails (no match) with bat.
?Marks part of a pattern as one that can appear zero or one time in the input. For example, be? matches be in believe, be in bee, be in beep, and b in bat.
{ }Marks a part of a pattern as one that can appear an arbitrary number of times in a specific range. For example, be{2} matches b followed by at least two e characters. be{0,3} matches b followed by at most three e characters. be{2,3} matches b followed by at least two, but at most three e characters.
[]Creates character classes, which allow you to match any one of a set of characters. For example, [abc123] matches the characters a, b, c, 1, 2, or 3.
-Specifies a range of characters. For example, [a-z] matches any lowercase letter. [a-zA-Z0-9] matches any lowercase or uppercase letter or any digit.

You also can use a character class to match any character not in a given set by adding a caret (^) to the beginning of the class. For example, [^0-9] matches any character that is not a digit. [^a-zA-Z0-9] matches any character that is not a lowercase or uppercase letter and also not a digit.
( )Indicates partial matches. Separate possible matches in a regular expression with a horizontal bar (|). For example, (cat|dog) catcher matches cat catcher or dog catcher and remembers the first part of the match (cat or dog) in the first partial match.

You also can use multiple partial matches.

For example, (a|the) (cat|dog) matches a cat, a dog, the cat, or the dog and remembers the first word (a or the) in the first partial match and the second word (cat or dog) in the second partial match.

((fire|police)(wo)?man) Smith matches fireman Smith, policeman Smith, firewoman Smith, or policewoman Smith. partial match 1 is fireman, policeman, firewoman, or policewoman; partial match 2 is fire or police; and partial match 3 is " " (empty string, indicating a man, because the ? indicates that wo can appear 0 or one times) or wo (indicating a woman).
|Indicates multiple possible matches. For example, cat|dog matches cat in catcher or dog in big dog.
^Anchors a match to the beginning of a string. For example, ^dog matches dog in dog catcher but not the dog.
$Anchors a match at the end of a string when used as the last character of a pattern. For example, dog$ matches dog in the dog but not dog catcher.
\Cancels the interpretation of any special character in this list.

The following escaped expressions have special meanings:
  • \b - Represents a word boundary. A word boundary is a character that is not a word character adjacent to a character that is a word character and vice versa. A word character is an alphanumeric character or an underscore (_). For example, \bhat matches hat in hatchet but not in that. hat\b matches hat in that but not in hatchet. \bhat\b matches hat in hat but not in that or hatchet.
  • \c - Matches any control or non-printing character; includes any code point in the character set that does not represent a written symbol
  • \w - Matches any word character; equivalent to [a-zA-Z0-9_]
  • \W - Matches any non-word character; equivalent to [^a-zA-Z0-9_]
  • \d - Matches any digit character; equivalent to [0-9]
  • \D - Matches any non-digit character; equivalent to [^0-9]
  • \s - Matches any white space character; includes space, newline, tab, carriage return, and so on
  • \S - Matches any non-white space character
  • \n - Matches a newline character
  • \t - Matches a tab character
  • \r - Matches a carriage return character
  • \f - Matches a formfeed character
  • \031 - Matches an octal character (31 octal in this case)
  • \x3F - Matches a hexadecimal character (3F hexadecimal in this case)

Tips

To anchor a match at the beginning and end of a string, use a caret (^) as the first character in a pattern and a dollar sign ($) as the last character of a pattern. For example, ^dog$ matches dog in dog but not dog catcher or the dog.

(cat | dog) \1 matches cat cat or dog dog but not cat dog or dog cat.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit