# Split expression function regex query

**URL:** <https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100>\
**Category:** Ignition\
**Created:** [November 28, 2018, 2:03am UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100 "2018-11-28T02:03:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 28, 2018, 2:03am UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/1 "2018-11-28T02:03:59Z")

</div>

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:

```auto
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/](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…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 28, 2018, 2:36am UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/2 "2018-11-28T02:36:42Z")

</div>

Maybe you just need the [substring()](https://docs.inductiveautomation.com/display/DOC79/substring) function?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 28, 2018, 2:54am UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/3 "2018-11-28T02:54:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [November 28, 2018, 7:46am UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/4 "2018-11-28T07:46:46Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 28, 2018, 1:07pm UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/5 "2018-11-28T13:07:09Z")

</div>

> [@c.bertulli](#):
>
> best solution I have for you

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

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [November 28, 2018, 1:50pm UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/6 "2018-11-28T13:50:29Z")

</div>

> [@nminchin](#):
>
> 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..

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.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [November 28, 2018, 2:31pm UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/7 "2018-11-28T14:31:14Z")

</div>

😅 I didn’t noticed

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 3, 2018, 4:54am UTC](https://forum.inductiveautomation.com/t/split-expression-function-regex-query/21100/8 "2018-12-03T04:54:56Z")

</div>

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