Split expression function regex query

I’m trying to use the split expression function using a regex expression, but cannot get this working…

I want to pull out the R G B values from a HEX colour (e.g. “#FF23DE”) using:

R = split(replace({New Template.Colour_HEX},'#',''), "[0-9a-fA-F]{2}")[0,0]
G = split(replace({New Template.Colour_HEX},'#',''), "[0-9a-fA-F]{2}")[1,0]
B = split(replace({New Template.Colour_HEX},'#',''), "[0-9a-fA-F]{2}")[2,0]

but this just give an error ArrayIndexOutOfBoundsException: 1
The dataset i get is 0R x 1C

I’ve tried this expression in a regex tester (https://regexr.com/) and it works as expected.
I know I can work around this using left() and right(), but I’d like to get it working with regex.

Thanks in advance.

Edit:
I just realised that the regex is what the split is looking for as text to split the string by, not the logic to use to split it… in which case I’m not sure how you could use a regex expression to your advantage?

In any case, can I achieve what I need using split and regex? My thoughts now would be no…

Maybe you just need the substring() function?

I could use that as well, but I’d like to know if it’s possible to use the split function, not just for this example, but for future reference.

I don’t think you can use split() for achieve your goal :frowning:
The best solution I have for you right now is:

HEX_Color = "#FF23DE"
HEX_Color = HEX_Color.lstrip('#')
RGB = tuple(int(HEX_Color[i:i+2], 16) for i in (0, 2 ,4))
print RGB

The OP is looking for an expression function or combination, not jython.

This is correct. What you need is a "find" or "match" function. Sadly, this is not present in the expression language (it is in Python, and could be offered by an independent module).

But split is not usable for your purpose, whatever matches the regex will be removed from the result.

:sweat_smile: I didn’t noticed

Thanks guys. I will use the other string functions instead.