添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

regex.extract( string , expression [, substitution ] [, no_match])


Returns the result of extracting the regular expression from the string, optionally with a substitution expression and a specified result if no match is found.Returns an empty string, or the string specified in no_match if the expression does not match. If the string specified was none , an empty string is returned.


The optional substitution expression is used to store groups that match the search expression. The first group is stored in \1 , the second in \2 , and so forth. For example:

// Extract the version using group 1 of the regular expression.
version := regex.extract(process.cmd, path_regex, raw "\1", no_match := 'No match.');

A versioning string is of the form "Version 2.7.182 patch 69". To extract the patch number, the following function is used:

patch := regex.extract(cmdResult.result, regex 'patch (\d+)',
                          raw '\1', no_match := 'Unsupported.');

The expression patch (\d+) matches patch 69 in the versioning string and it contains the first group matching \1 which is 69 . If the versioning string was "Version 2.7.182 patch 69 patch 70" then the second group matching \2 is 70 .

If the versioning string was "Version 2.7.182", the function would return "Unsupported."

acceptance of BMC’s Terms of Use . BMC, the BMC logo, and other BMC marks are assets of BMC Software, Inc. These trademarks are registered may be registered in the U.S. and in other countries.