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

Match Regular Expression Function

NI LabVIEW 8.6 Help
June 2008

NI Part Number:
371361E-01

»View Product Info

Owning Palette: String Functions

Installed With: Base Package

Searches for a regular expression in the input string beginning at the offset you enter and, if it finds a match, splits the string into three substrings and any number of submatches. Resize the function to view any submatches found in the string.

For components utilizing the PCRE library package, the following copyright notice applies.

Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright by the University of Cambridge, England.

Details  

multiline? sets whether or not to treat the text in input string as a multiple-line string. This affects how the ^ and $ characters handle matches. When FALSE (the default), entering "^" matches the beginning of the line in input string only and entering "$" matches the end of input string only. When TRUE, "^" matches the beginning of any line in input string and "$" matches the end of any line in input string.
ignore case? specifies whether the string search is case sensitive. If FALSE (default), the string search is case sensitive.
input string specifies the input string the function searches. This string cannot contain null characters.
regular expression specifies the pattern you want to search for in input string. If the function does not find a match, whole match and after match contain empty strings, before match contains the entire input string, offset past match returns –1, and all submatches outputs return empty strings. Place any substrings you want to search for in parentheses. The function returns any substring expressions it finds in substring 1..n. This string cannot contain null characters.
offset determines the number of characters into input string at which the function starts searching for search string.
error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. This VI or function runs normally only if no error occurred before this VI or function runs. If an error occurs while this VI or function runs, it runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use exception control to treat what is normally an error as no error or to treat a warning as an error. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
status is TRUE (X) if an error occurred before this VI or function ran or FALSE (checkmark) to indicate a warning or that no error occurred before this VI or function ran. The default is FALSE.
code is the error or warning code. The default is 0. If status is TRUE, code is a nonzero error code. If status is FALSE, code is 0 or a warning code.
source specifies the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning. The default is an empty string.
before match returns a string containing all the characters before the match.
whole match contains all the characters that match the expression entered in regular expression. Any substring matches the function finds appear in the submatch outputs.
after match contains all characters following the matched pattern entered in regular expression.
offset past match returns the index in input string of the first character after the last match. If the VI does not find a match, offset past match is –1.
error out contains error information. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out front panel indicator and select Explain Error from the shortcut menu for more information about the error.
status is TRUE (X) if an error occurred or FALSE (checkmark) to indicate a warning or that no error occurred.
code is the error or warning code. If status is TRUE, code is a nonzero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning.

Match Regular Expression Details

The Match Regular Expression function gives you more options for matching strings but performs more slowly than the Match Pattern function.

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

Use regular expressions in this function to refine searches.

Certain regular expressions that use repeated grouped expressions (such as (.|\s)* or (a*)*) require significant resources to process when applied to large input strings. In some cases a stack overflow may occur on large input strings. Some regular expressions may recurse repeatedly while attempting to match a large string which may eventually overflow the stack. For example, the regular expression (.|\n)*A and a large input string may cause LabVIEW to crash. To avoid recursion, you can rewrite the regular expression (.|\n)*A as (?s).*A. The (?s) notation indicates that a period matches new lines. You also can rewrite the expression as [^A]*A.

The following table shows examples of regular expressions you can use with this function. Some of these examples use special characters to refine the search.

Characters to Find Regular Expression
VOLTS VOLTS
A space, 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]+
One or more characters other than digits [^0-9]+
The word Level only if it begins at the offset position in the string ^Level
The word Volts only if it appears at the end of the string Volts$
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, and so on. [cd][ao][tg]
cat or dog cat|dog
dog, cat dog, cat cat dog,cat cat cat dog, and so on ((cat )*dog)
One or more of the letter a followed by a space and the same number of the letter a, that is, a a, aa aa, aaa aaa, and so on (a+) \1

Resources


 

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