labview的正则表达式语法 来自labview的帮助
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Special Characters for Match Regular Expression(正则表达式) and Search and Replace String
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 The Match Regular Expression function does not support null characters in strings. Also, a
pattern can return a successful match of an empty string. If a pattern does not return a successful
match, the offset past match will return –1.
Regular expression support is provided by the PCRE library package. The license under which the PCRE library package is redistributed can be found on the Copyright page at Important Information»Copyright on the Contents tab.
Refer to the PCRE Web site at for more information about Perl Compatible Regular Expressions.
Special
Character
Interpreted 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, the pattern b* matches b in baac. The pattern b*, however, also matches an empty string or abbc, returning a successful match with whole match returning an empty string.
+ 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.
Note Anchoring the match at the beginning and end of the string requires the whole string to match. Use backreferences to refer to previous partial matches in a regular expression. To specify a backreference, use \1 to refer to the first partial match, \2 to refer to the second, and so on. For example (cat | dog) \1 matches cat cat or dog dog but not cat dog or dog cat.
Special Characters for Search and Replace String
Use these special characters in the replace string input of the Search and Replace String function.
Special
Character
Interpreted As
$n Inserts the string you specify before the grouped match you specify. For example, if you use the input string The cat sleeps, the search string (cat), and the replace string big $1, the function places big in front of cat. The cat sleeps becomes The big cat sleeps.
Use (|) in the regular expression in the input string and $n in the replace string to search for multiple grouped matches. For example, if you use the input string The dog hurt the cat, the search string (cat|dog), and the replace string big $1, the function places big in front of cat or dog, depending on which string the function finds first. The dog hurt the cat becomes The big dog hurt the cat.
$2 matches the second group, $3 matches the third group, and so on. For example, if you use the input string The big dog hurt the little cat, the search string (big|little) (cat|dog), and the replace string nice $1 red $2, the function places nice in front of big or little and red before cat or dog. The result string reads The nice big red dog hurt the little cat.
${n} Inserts the string you specify before the grouped match you specify. Use ${n} to search more than nine grouped matches. $12 searches only the first grouped match, because the function reads only the first number. However, ${12} finds the twelfth grouped match.
\$n Cancels the interpretation of any special character you use in the replace string. For example, use \$1 to type the literal characters $1.
Use \\ to indicate a literal backslash.
Submit feedback on this topic。