fn.analyzeString( in as String?, regex as String, [flags as String] ) as element(s.results)
The result of the function is a new element node whose string value is the original string, but which contains markup to show which parts of the input match the regular expression.
Parameters | |
---|---|
in | The string to start with. |
regex | The regular expression pattern to match. |
flags | The flag representing how to interpret the regular expression. One of "s", "m", "i", or "x", as defined in http://www.w3.org/TR/xpath-functions/#flags. |
fn.analyzeString('Tom Jim John',"Jim"); => <s:analyze-string-result> <s:non-match>Tom </s:non-match> <s:match>Jim</s:match> <s:non-match> John</s:non-match> </s:analyze-string-result>
fn.analyzeString('Tom Jim John',"(Jim)"); => <s:analyze-string-result> <s:non-match>Tom </s:non-match> <s:match> <s:group nr="1">Jim</s:group> </s:match> <s:non-match> John</s:non-match> </s:analyze-string-result>
fn.analyzeString('Tom Jim John',"((Jim) John)"); => <s:analyze-string-result> <s:non-match>Tom </s:non-match> <s:match> <s:group nr="1"> <s:group nr="2">Jim</s:group> John </s:group> </s:match> </s:analyze-string-result>
fn.analyzeString("http://example.com/", "\\w+"); // note that you have to escape the escape character in JavaScript => <result xmlns="http://www.w3.org/2005/xpath-functions"> <match>http</match> <non-match>://</non-match> <match>example</match> <non-match>.</non-match> <match>com</match> <non-match>/</non-match> </result>