When using groups within a regex, it is usually possible to "back reference" to such a group via its number (or name), such as "\1" to reference to the first (capturing) group. Am I right that this is not supported with SQL Anywhere? Here's a sample: -- search for a number followed by non-digits and a further number select regexp_substr('abc-101-abd-102-abe', '(\\d+)\\D+\\d+'); -- -> returns "101-abd-102" -- If I want the match to restrict to those cases -- where the first and second number are identical, -- that requires a backreference via \1, such as select regexp_substr('abc-101-abd-102-abe', '(\\d+)\\D+\\1'); -- should not match select regexp_substr('abc-101-abd-101-abe', '(\\d+)\\D+\\1'); -- should match However, adding '\\1' to the regexp pattern leads to SQLCODE -1135 aka "Invalid regular expression: unsupported syntax in '(\d+)\D+\1'" I'm using 16.0.0.2704 but I guess the regex support has been unchanged for quite a number of versions. |
Hi Volker, SQL Anywhere does NOT support back references in regular expressions. See https://help.sap.com/viewer/40c01c3500744c85a02db71276495de5/17.0/en-US/81735cab6ce21014b8a287b4fbb8fdc0.html for the list of escaped characters supported, and note that back references are not listed. Ian Thanks for the confirmation. I noticed that list but was not sure as the docs also state:
which includes backreferences AFAIK.
(18 Sep '18, 09:49)
Volker Barth
Replies hidden
. . . cannot . . . resist . . . must . . . post . . . this :)
(19 Sep '18, 09:34)
Breck Carter
Particularly funny as I came across that one by chance (?) yesterday, too:)
(19 Sep '18, 10:02)
Volker Barth
|
If backreferences are not supported, that would explain the following doc quote IMHO:
If backreferences are not supported, a group needs no capturing, and so a "capturing group" and a "non-capturing group" would be equivalent...