
On 08/10/15 12:00, imad hajj chahine wrote:
Hi,
Monetdb is using pcre library for regular expression support, and using this function we can allow SQL to use the regex library:
CREATE FUNCTION "pcre_replace" (origin string, pat string, repl string,flags string) RETURNS string EXTERNAL NAME pcre."replace";
I want to use regex for date conversion to the format supported by monetdb (yyyy-MM-dd), I have the following format dd/MM/yyyy, and i am trying to run the following with no success:
select pcre_replace('15/10/2015', '^(3[01]|[12][0-9]|0?[1-9])/(1[012]|0?[1-9])/([0-9]{4})$', '\\3-\\2-\\1', 'i')
select pcre_replace('15/10/2015', '^(3[01]|[12][0-9]|0?[1-9])/(1[012]|0?[1-9])/([0-9]{4})$', '{3}-{2}-{1}', 'i')
select pcre_replace('15/10/2015', '^(?<day>3[01]|[12][0-9]|0?[1-9])/(?<month>1[012]|0?[1-9])/(?<year>[0-9]{4})$',
'\\k<year>-\\k<month>-\\k<day>', 'i')
My question is, is backreference supported in the replacement string; if yes, whats is the right syntax to use to reference the detected groups, if no, is there a clever way then using substring?
Thanks
_______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list
Backreference is unfortunately not supported. It looks like the PCRE library provides everything needed to do it yourself. In other words, there is no call to the library to do replacements, all that is provided is the search which will return the offsets of the groups to the application. It is up to the application to implement replacement. And thus far nobody felt the need to implement this in MonetDB. I also don't see a quick and clever way to do this using substring. The problem for substring is the optional 0 in your day and month patterns. If you had fixed sized strings for days and months it would be fairly easy. -- Sjoerd Mullender