Table Transformer: Regex replace
Asked by Jan Loewe:

I would like to perform a replace in a result using a regular expression. Unfortunately something like

```
SELECT T1.'animals'->replace('/Cats/g',"Dogs") FROM T1
```

does not seem to work, because it seems that I cannot convince JavaScript to treat the search string as a regular expression.

Any ideas how to solve that?


Answers:
author: Stiltsoft support
body: Hi [@Jan Loewe](/t5/user/viewprofilepage/user-id/5591655) ,

Seems that you are using the [Table Transformer](https://docs.stiltsoft.com/tfac/dc-server/table-transformer-42241552.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro that comes with the [Table Filter, Charts \& Spreadsheets for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-charts-spreadsheets-for-confluence?tab=overview&hosting=datacenter&utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) app that we develop.

The REPLACE function works only with strings, so, it is an expected behavior.

If your case looks similar to the screenshot below and you need to replace only one regex match, you may try the following workaround:

SELECT \*,  
REPLACE(T1.'animals', MATCH_REGEXP(T1.'animals', "\\d+Cats", "g"), "Dogs") AS 'new animals'  
FROM T1

![Fri 4-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/347356iE481038140F2B69C/image-size/large?v=v2&px=999 "Fri 4-1.png")

To find and replace several regex matches, you'll need the REGEXP_REPLACE function or smth similar that is currently not supported by the macro - seems that it's a rare case and you are the first customer with such request.

So, I've created a new ticket for our internal roadmap and attached the link to this question - once the new function is introduced, we'll return here and notify you.

comments: author: Jan Loewe
body: Thanks for the reply, I'll be looking forward to the new functionality.

For the records, in the meantime, I found some kind of workaround using SEARCH:

I go from:

![1.png](https://community.atlassian.com/t5/image/serverpage/image-id/347741i12E6B7343E868C4C/image-size/large?v=v2&px=999 "1.png")

To:

![2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/347742i1E7A3A9B5AE7DA4B/image-size/large?v=v2&px=999 "2.PNG")

Using:

```
SEARCH / AS @a EX(IFNULL('log'->'split'(";"), " "->'split'("."))) /
RETURN(@a->'id' AS id, REPLACE(_, MATCH_REGEXP(_, "\(\d{2}:\d{2}\)"), "") AS 'log')
FROM T1
```

This is btw. my use-case: I have to strip timestamps from multiple entries which are unfortunately in a single field.

Finally, I join the results again using a pivot table:

![4.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/347746iA4C2202C11FD7DE0/image-size/large?v=v2&px=999 "4.PNG")![5.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/347747i51DEF9300A4964B6/image-size/large?v=v2&px=999 "5.PNG")

Which finally yields the desired result:

![6.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/347748i60BF719785A12D86/image-size/large?v=v2&px=999 "6.PNG")


author: Stiltsoft support
body: As I see, we do have a simplified example with the SEARCH function in our documentation <https://docs.stiltsoft.com/tfac/dc-server/custom-transformation-use-cases-with-advanced-sql-queries-42241587.html#CustomTransformationusecaseswithadvancedSQLqueries-Splittingcellvaluesinacolumntodifferentrows>

and you've amplified it with REPLACE and MATCH_REGEXP that are currently supported.

Thank you for the thorough description! It may definitely help other users with similar use cases.


author: Kristian Klima
body: There was a Search \& Replace app for Confluence Server, and it was free or dirt cheap, that did Regex...

Perhaps there's a way how to get it and get it run... [https://marketplace.atlassian.com/apps/1212823/search-and-replace?tab=overview\&hosting=server](https://marketplace.atlassian.com/apps/1212823/search-and-replace?tab=overview&hosting=server)


author: John Funk
body: Hi Jan - Welcome to the Atlassian Community!

Where are you running this?


Tags: confluence-data-center

confluence-server

data-center

filter

table

table-filter-and-charts

table-filter-charts-spreadsheets

table-transformer