MarkLogic Server 11.0 Product Documentation
fn.analyzeString

fn.analyzeString(
   in as String?,
   regex as String,
   [flags as String]
) as element(s.results)

Summary

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.

Example

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>

Example

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>

Example

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>

Example

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>
Powered by MarkLogic Server | Terms of Use | Privacy Policy