Home mm2k6 Help Files Procedures Regular Expression Matching
11 | 12 | 2017
Regular Expression Matching

Version 4.1 brings a new way to match text within script by introducing two regular expression matching procedures. Think of these are substring searches on steroids. @regex(RegexPattern,string) lets you check for a match and @regexMatch(RegexPattern,string) lets you check for a match and fills an array with the submatches found.

@regex(RegexPattern, stringToMatch)  returns true if a complete match is made false otherwise. The string to match can be any text, variable, procedure or combination. The regular expression can be text, variable, procedure or any combination. In fact storing patterns in variables is recommended because of how they usually involve special characters which need escaping and because they tend to get long and very complicated looking.

@regexMatch(RegexPattern, stringToMatch) returns the string that matches the pattern and fills the session level system array called RegexSubMatches with the submatches. The element indexes match the sub match number.

For details of the syntax and use of regular expressions check out the Boost.org documentation ar http://www.boost.org/doc/libs/1_37_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html 

Both of these procedures use the same regular expression syntax as the new version of /scrollgrep. Read the details in the scrollgrep part of the Miscellaneous Commands page.