I'm building two hybrid expressions in SQL Alchemy where I want to select i) all the digits before and ii) all the digits after a hyphen in a string.
Given the string 6-12(1) I'd like the outputs 6 and 12 respectively.
Following this answer I figured I'd need r"(\d+)-" for i) so:
@digits_before.expression
def digits_before(cls):
return func.regexp_substr(cls.string_field, r"(\d+)-")
However, this returns 6- for the record in question.
Looking at the SQL that's generated the regex string is reduced to '(d+)-' - could this be why?
What are the correct two regex strings I need to use?
Thanks in advance.