# How to Extract color out of HTML text in Tag

**URL:** <https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090>\
**Category:** Ignition\
**Tags:** vision, ignition80\
**Created:** [March 4, 2021, 12:09pm UTC](https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090 "2021-03-04T12:09:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [March 4, 2021, 12:09pm UTC](https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090/1 "2021-03-04T12:09:34Z")

</div>

I have a string tag in UDT which consist HTML value of color as below:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/20ae98c26d52ed2695210c0bb111236884b40f52.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/3/c3e8d1207eeb329559dab17af99740c163bc28d6.png)

Is there any way to extract this color as I want to use this to fill background of label on vision screen.

Thanks so much,  
Kaushik

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 4, 2021, 1:02pm UTC](https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090/2 "2021-03-04T13:02:16Z")

</div>

Using a regex can do this for you.

```auto
def getHtmlColor(testString):
	import re

	regex = "<font color=(.{,})>"
	match = re.search(regex, testString)
	if match:
		return match.groups()[0][1:-1]
	else:
		return None

print getHtmlColor("<html><font color='blue'>1.55")

```

Output:

```nohighlight
blue

```

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [March 4, 2021, 1:19pm UTC](https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090/3 "2021-03-04T13:19:49Z")

</div>

@JordanCClark thanks. Although, I was looking for an inbuilt function, this worked great.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 4, 2021, 2:11pm UTC](https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090/4 "2021-03-04T14:11:07Z")

</div>

It _could_ be done in an expression.

```auto
split({[~]path/to/tag}, "['"+'"]')[1,0]

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 4, 2021, 5:22pm UTC](https://forum.inductiveautomation.com/t/how-to-extract-color-out-of-html-text-in-tag/44090/5 "2021-03-04T17:22:20Z")

</div>

> [@JordanCClark](#):
>
> Using a regex can do this for you.

> <https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454>

> [@kaushik.shah](#):
>
> I have a string tag in UDT which consist HTML value of color as below:

I would not rely on this HTML coloring to work in the tag browser (as in, it's absolutely a bug that it works at all). Why not just add a new property to the tag that you can use as the color?
