Stata 15 help for mf_regex


[M-5] regexm() -- Regular expression match


real matrix regexm(string matrix s, string matrix re)

string matrix regexr(string matrix s1, string matrix re, string matrix s2)

string matrix regexs(void)

string matrix regexs(real scalar n)


regexm(s, re) returns one or zero, corresponding to a match or no match, of regular expression string re against s.

regexr(s1, re, s2) returns the result of replacing the first substring within s1 that matches re with s2. If s1 contains no string that matches the regular expression re, the unaltered s1 is returned.

regexs(void) returns all subexpressions from a previous regexm() match as a matrix of strings.

regexs(n) returns subexpression n from a previous regexm() match, where 0 < n < 10. Subexpression 0 is reserved for the entire string that satisfied the regular expression.

When s, s1, s2, and re are not scalar, these functions return element-by-element results.


The syntax for these undocumented functions may change in the future.


regexm(s, re), regexr(s1, re, s2), s, s1, re, s2: r x c result: r x c



Source code

Functions are built in.

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index