[SOLVED] Invalid regular expression in Marklogic


I am trying to match stand alone numbers in some comma separated string , after splitting this string by commas and save it to variable $i, I use this regular expression:

fn:matches(fn:normalize-space($i), "(?<!\S)\d+(?!\S)")
  • Example : (123) should return true.
  • Example: (abc123) sholud return false.
  • Example: (abc 123 abc) should return false.

But, it gives me:

[1.0-ml] XDMP-REGEX: (err:FORX0002) .

What is the wrong with this expression?


Lookahead and lookbehind are not supported in XQuery regex expressions.

However, you don’t need them if you are just looking to verify that the value is purely numeric values. You can anchor the expression to the beginning and end of the value and ensure that everything in-between is a number:

fn:matches(fn:normalize-space($i), "^\d+$")

Answered By – Mads Hansen

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *