Match Regular Expression function: Difference between revisions
Added input parameters |
mNo edit summary |
||
| Line 19: | Line 19: | ||
*If you set '''multiline?''' to FALSE (default), when you enter ^ at the beginning of a regular expression, the expression matches only the beginning of the string in '''input string'''. When you enter $ at the end of a regular expression, the expression matches only the end of the string in '''input string'''. | *If you set '''multiline?''' to FALSE (default), when you enter ^ at the beginning of a regular expression, the expression matches only the beginning of the string in '''input string'''. When you enter $ at the end of a regular expression, the expression matches only the end of the string in '''input string'''. | ||
*If you set '''multiline?''' to TRUE, ^ matches the beginning of any line in '''input string''' and $ matches the end of any line in '''input string'''. | *If you set '''multiline?''' to TRUE, ^ matches the beginning of any line in '''input string''' and $ matches the end of any line in '''input string'''. | ||
'''Note''' The ^ character anchors the match to the beginning of a string when used as the first character of a pattern. If you add ^ to the beginning of a character class immediately after an open square bracket, the expression matches any character not in a given character class. | |||
|- | |- | ||
! [[File:Boolean.png|link=Boolean data type]] | ! [[File:Boolean.png|link=Boolean data type]] | ||
| Line 44: | Line 45: | ||
| No | | No | ||
| '''error in''' describes error conditions that occur before this node runs. This input provides [[Error Cluster data type|standard error]] in functionality. | | '''error in''' describes error conditions that occur before this node runs. This input provides [[Error Cluster data type|standard error]] in functionality. | ||
|- | |||
! [[File:String Indicator.png|link=String data type]] | |||
| '''before match''' | |||
| No | |||
| '''before match''' returns all the characters before the match. | |||
|- | |||
! [[File:String Indicator.png|link=String data type]] | |||
| '''whole match''' | |||
| No | |||
| '''whole match''' returns all the characters that match the expression entered in '''regular expression'''. Any substring matches the function finds appear in the submatch outputs. | |||
|- | |||
! [[File:String Indicator.png|link=String data type]] | |||
| '''after match''' | |||
| No | |||
| '''after match''' returns all the characters after the match. | |||
|- | |||
! [[File:I32 Indicator.png|link=I32 data type]] | |||
| '''offset past match''' | |||
| No | |||
| '''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''' returns –1. | |||
|- | |||
! [[File:Error Cluster Indicator.png|link=Error Cluster data type]] | |||
| '''error out''' | |||
| No | |||
| '''error out''' contains error information. This output provides [[Error Cluster data type|standard error]] out functionality. | |||
|} | |} | ||
== | === Details === | ||
'''Note''' The Match Regular Expression function does not support null characters in strings. If you include null characters in strings you wire to this function, LabVIEW returns an error and the function may return unexpected results. | |||
*Regular expression support is provided by the PCRE library package. Refer to <National Instruments>\_Legal Information directory for more information about the license under which the PCRE library package is redistributed. | |||
*Refer to the PCRE website at [http://www.pcre.org www.pcre.org] for more information about Perl Compatible Regular Expressions. | |||
*The Match Regular Expression function gives you more options for matching strings but performs more slowly than the [[Match Pattern function]]. | |||
*Use regular expressions (regex) in this function to refine searches. | |||
====Avoiding Stack Overflow==== | |||
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. | |||
====Grouping Patterns for Submatches==== | |||
You can capture submatches by placing parentheses ( ) around a portion of a regular expression that you want the function to return as a submatch. For example, the regular expression (el.)..(L..) returns two submatches in the input string Hello LabVIEW!: ell and Lab. Each submatch corresponds to a character group in the order that the character group appears in the regular expression. In this example, '''submatch 1''' is ell and '''submatch 2''' is Lab. | |||
If you nest a character group within another character group, the regular expression creates a submatch for the outer group before the inner group. For example, the regular expression (.(el.).).(L..) returns three submatches in the input Hello LabVIEW!: Hello, ell, and Lab. In this example, '''submatch 1''' is Hello because the regular expression matches the outer character group before the inner group. | |||
== Tips and tricks == | == Tips and tricks == | ||
* Use back references to refer to previous partial matches in a regular expression. <code>\1</code> refers to the first partial match, <code>\2</code> to the second, and so on. For example, <code>(cat|dog) \1</code> matches "cat cat" or "dog dog" but not "cat dog" or "dog cat". | * Use back references to refer to previous partial matches in a regular expression. <code>\1</code> refers to the first partial match, <code>\2</code> to the second, and so on. For example, <code>(cat|dog) \1</code> matches "cat cat" or "dog dog" but not "cat dog" or "dog cat". | ||
== XNode == | |||
This node is an example of how [[XNode]]s are used as a primitive node in LabVIEW. It utilizes the [[AdaptToInputs (XNode Ability)|AdaptToInputs]], [[Bounds (XNode Ability)|Bounds]], [[DisplayName (XNode Ability)|DisplayName]], [[GenerateCode (XNode Ability)|GenerateCode]], [[GrowInfo (XNode Ability)|GrowInfo]], [[Help (XNode Ability)|Help]], [[Image (XNode Ability)|Image]], [[Initialize (XNode Ability)|Initialize]], [[Size (XNode Ability)|Size]], [[Terms (XNode Ability)|Terms]], and [[UpdateStateWithRef (XNode Ability)|UpdateStateWithRef]] abilities. The abilities used can be viewed after enabling the [[LabVIEW configuration file/Miscellaneous#XNodeWizardMode|XNodeWizardMode]] INI flag. Many of the ability VIs are password protected. | |||
== History == | == History == | ||
{{ambox|text=History information is needed. What changes have occurred over previous versions?}} | |||
{| class="wikitable" | |||
! Version | |||
! Change(s) | |||
|- | |||
|[[File:LV2018.png|frameless|border|64x64px|LabVIEW 2018|link=LabVIEW 2018]] | |||
|More info to come. | |||
|} | |||
== See also == | == See also == | ||
*[[Match Pattern function]] | |||
*[[XNode]]s | |||
== External links == | == External links == | ||
* [https://regex101.com/ RegEx101] - A great resource for trying out your regular expression. Contains help, syntax highlighting, etc. '''Note''' LabVIEW uses PCRE, use this when using the website. | |||
[[Category:String Palette]] | [[Category:String Palette]] | ||
Revision as of 15:17, 1 February 2021
| Object information | |
|---|---|
| Owning palette(s) | String palette |
| Type | Function |
| Requires | Basic Development Environment |
| Icon | |
The Match Regular Expression function searches for a regular expression in the input string beginning at the offset you enter. If the function finds a match, it splits the string into three substrings and any number of submatches. Resize the function to view any submatches found in the string.
Usage

| Data Type | Name | Required? | Description |
|---|---|---|---|
| multiline? | No | multiline? specifies whether to treat the text in input string as a multiple-line string. This setting affects how the ^ and $ characters handle matches.
Note The ^ character anchors the match to the beginning of a string when used as the first character of a pattern. If you add ^ to the beginning of a character class immediately after an open square bracket, the expression matches any character not in a given character class. | |
| ignore case? | No | ignore case? specifies whether the string search is case sensitive. If FALSE (default), the string search is case sensitive. | |
| input string | Yes | input string specifies the input string the function searches. This string cannot contain null characters. | |
| regular expression | Yes | 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 | No | offset specifies the number of characters into input string at which the function starts searching for search string. | |
| error in | No | error in describes error conditions that occur before this node runs. This input provides standard error in functionality. | |
| before match | No | before match returns all the characters before the match. | |
| whole match | No | whole match returns all the characters that match the expression entered in regular expression. Any substring matches the function finds appear in the submatch outputs. | |
| after match | No | after match returns all the characters after the match. | |
| offset past match | No | 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 returns –1. | |
| error out | No | error out contains error information. This output provides standard error out functionality. |
Details
Note The Match Regular Expression function does not support null characters in strings. If you include null characters in strings you wire to this function, LabVIEW returns an error and the function may return unexpected results.
- Regular expression support is provided by the PCRE library package. Refer to <National Instruments>\_Legal Information directory for more information about the license under which the PCRE library package is redistributed.
- Refer to the PCRE website at www.pcre.org for more information about Perl Compatible Regular Expressions.
- The Match Regular Expression function gives you more options for matching strings but performs more slowly than the Match Pattern function.
- Use regular expressions (regex) in this function to refine searches.
Avoiding Stack Overflow
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.
Grouping Patterns for Submatches
You can capture submatches by placing parentheses ( ) around a portion of a regular expression that you want the function to return as a submatch. For example, the regular expression (el.)..(L..) returns two submatches in the input string Hello LabVIEW!: ell and Lab. Each submatch corresponds to a character group in the order that the character group appears in the regular expression. In this example, submatch 1 is ell and submatch 2 is Lab.
If you nest a character group within another character group, the regular expression creates a submatch for the outer group before the inner group. For example, the regular expression (.(el.).).(L..) returns three submatches in the input Hello LabVIEW!: Hello, ell, and Lab. In this example, submatch 1 is Hello because the regular expression matches the outer character group before the inner group.
Tips and tricks
- Use back references to refer to previous partial matches in a regular expression.
\1refers to the first partial match,\2to the second, and so on. For example,(cat|dog) \1matches "cat cat" or "dog dog" but not "cat dog" or "dog cat".
XNode
This node is an example of how XNodes are used as a primitive node in LabVIEW. It utilizes the AdaptToInputs, Bounds, DisplayName, GenerateCode, GrowInfo, Help, Image, Initialize, Size, Terms, and UpdateStateWithRef abilities. The abilities used can be viewed after enabling the XNodeWizardMode INI flag. Many of the ability VIs are password protected.
History
| |
History information is needed. What changes have occurred over previous versions? |
| Version | Change(s) |
|---|---|
| More info to come. |
See also
External links
- RegEx101 - A great resource for trying out your regular expression. Contains help, syntax highlighting, etc. Note LabVIEW uses PCRE, use this when using the website.