1

I have an XML as

<Root>
<Child><p><b>The Perfect Fit for Any Space</b></p> <p>Challenging the essence of how we define a desktop PC, GIGABYTE engineers have developed an ultra compact PC with a brushed aluminum surface chassis design. Ideal for a broad range of computing applications at home or in the office, the BRIX expounds sheer simplicity and convenience. With a broad choice of processors covering the entire performance spectrum, the BRIX sets a new standard for desktop miniaturization that makes it perfect as a discreet HTPC/multimedia hub, an ultra-low power PC for the family, an office PC or as a digital signage unit.</p> <p><b>Intel&reg; Celeron&reg; Processor</b><br /><br />GIGABYTE BRIX supports Intel third-generation low-power quad-core SoC processors which feature power-efficient 10W Intel&reg; Celeron models. From a simple internet access point to a high end multimedia station, the GIGABYTE BRIX a broad range of usage scenarios and the ultimate space flexibility. GIGABYTE BRIX is expected to deliver up to 23% improvement in productivity over previous generation.</p> <p><b>Supports DDR4 Memory</b></p> <p>GIGABYTE BRIX provides a 128-bit memory controller that supports DDR4 at up to 2400MHz. DDR4 is a type of synchronous dynamic random-access memory with a double data rate and high bandwidth interface. The primary advantages of DDR4 over its predecessor, DDR3, include higher module density and lower voltage requirements, coupled with higher data rate transfer speeds.</p> <p><b>Connecting the Future - USB Type-C&trade;: The World's Next Universal Connector</b></p> <p><b>Reversible USB Type-C&trade; with USB 3.0</b><br />The USB Type-C&trade; is a new reversible connector that is loaded with useful features such as USB 3.0 support for 5 Gb/s transfer speed. </p> <p><b>USB 3.0 and Network Connectivity</b><br />GIGABYTE BRIX&trade; also includes a M.2 module offering IEEE 802.11ac Wi-Fi and the latest Bluetooth 4.2, providing connectivity for low power Bluetooth users to easily connect mobile devices.</p> <p><b>SuperSpeed 4K HD Entertainment</b></p> <p><b>Supporting the Newest Standards in Multimedia <br /></b>GIGABYTE ensures users won't be limited by the standards or connections on the BRIX, by including HDMI 2.0 and support for HDCP 2.2 users can rest assured that their device will be able to display content to its full potential. The BRIX supports native resolutions of 4K at 60Hz, presenting unrivaled visual clarity and stunning realism to owners of UHD displays.</p> <p><b>Multi-display productivity with HDMI 2.0 &amp; DisplayPort</b><br />BRIX supports up to three independent displays through HDMI 2.0 and a DisplayPort without the need for an additional graphics card. Support for two display is only possible with daisy-chain connections through Display Port.</p> <p><b>Graphics that Captivate</b></p> <p>Intel&reg; HD Graphics deliver 10% more performance than its predecessor. With the new media engine users are able to, watch, create, edit, share and game all with captivating visuals. This media engine offers HEVC 10-bit hardware acceleration which improves upon the 4K viewing and content creation performance significantly versus previous generation processors. The BRIX now has the ability to drive premium content up to 4K UHD, so users can enjoy amazing and vibrant multimedia experiences on compatible displays.</p> <p><b>2.5" Hard Drive Support</b></p> <p>Utilizing SATA III 6 Gb/s high speed data transfer technology, the GIGABYTE BRIXs supports the installation of one 2.5" SATA 6Gbps HDD or Solid State Drive (SSD) and one M.2 2280 SSD module. This allows for optimized storage configurations which combine fast M.2 performance with larger capacity 2.5" hard drive. </p></Child>
</Root>

let $a := /Root/Child/string()

When I do fn:matches($a, $a) it gives XDMP-REGEX error. I am not able to understand for which particular character it is failing. Error snipet

[1.0-ml] XDMP-REGEX: (err:FORX0002) fn:matches("<p><b>The Perfect Fit for Any Space</b></p> <p>Challenging the e...", "<p><b>The Perfect Fit for Any Space</b></p> <p>Challenging the e...") -- Invalid regular expression
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Nikunj Vekariya
  • 833
  • 5
  • 19
  • https://stackoverflow.com/a/1732454/10011003 - Don't use regex to parse html! – Nordle Dec 13 '18 at 11:24
  • It’s so much easier to help with coding problems if you send actual running code. – hunterhacker Dec 13 '18 at 11:46
  • 1
    You've shown us an element named `p` which you say is named `Child`, then you've shown us an XQuery fragment that doesn't reference either `p` or `Child`, and which you say is failing. And you haven't given full details of the error. Please take a little more care in describing your problem. – Michael Kay Dec 13 '18 at 12:23
  • 1
    From what you have posted in your question, it appears that you either have the literal string "elementValue" assigned to the `$a` variable. Although it wouldn't make sense, you would not get an error executing `fn:matches('elementValue', 'elementValue')`. It would return `true()`. At the same time, if `$a` was a reference to the "Child" element, then the second parameter should be a regex, not the value of `$a`. The second parameter of `fn:matches()` is supposed to be a regex to test against the first parameter. – Mads Hansen Dec 14 '18 at 02:39
  • Also, if you were to post the full error message to include the text after XDMP-REGEX, it would give a clue as to what values you had sent in and why the second parameter value is invalid. – Mads Hansen Dec 14 '18 at 02:43
  • @MadsHansen - sorry for vague description. Please find the error snippet and logic as well – Nikunj Vekariya Dec 14 '18 at 13:24
  • `When I do fn:matches($a, $a)...` don't do that. Why do you want to do that? The output will be true if `$a` contains no other regex meta-character than `.`, an error if it contains sequences of characters that make it invalid as a regex, or false if it is a valid regex that contains other meta-characters than `.`. – Aaron Dec 14 '18 at 13:26

1 Answers1

1

fn:matches() is used to test whether a regex matches a string. The second parameter needs to be a valid regex pattern.

Error Conditions A dynamic error is raised [err:FORX0002] if the value of $pattern is invalid according to the rules described in 5.6.1 Regular expression syntax.

The computed string value of that element is not a valid regex expression. There are characters, such as the / in that string that would need to be escaped. Also, though it is valid, unless you escape the ( and ) in that string, it won't be looking for those literal characters, it will try to create a regex capture group.

Rather than try to figure out how to turn a random string into a valid regex expression, just use the other string comparison options.

If you are trying to determine whether the atomized string value for that node is equal, then you can just compare the string values using either the eq or = operators:

$a eq $a

If you want to see if the second parameter is contained in the first parameters value, you can use fn:contains(), which expects simple strings (no regex patterns) as the parameter values:

fn:contains($a, $a)

If you are trying to test equality of two nodes, not simply their computed string values, then you can use fn:deep-equals(). But of course, the same variable will be equal, so it still doesn't make sense to compare fn:deep-equals($a, $a).

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147