Using RegEx in tMap

Five Stars kdv
Five Stars

Using RegEx in tMap

Hi All

 

I am using a tMap to read in some data, transform it and output a new file. 

I would like to use a regular expression to parse the string in one of the columns.  

As an example, here is a raw input string: 

 

Firstname Surname:Acme - 364315

 

I would like to be able to apply a regex to the above string to return only Firstname Surname

 

My syntax is totally wrong, but I am looking for something along the lines of row1.columname.parse("[^:]*") to go into the expression for that particular column

 

I understand there is a simple way to do this using the normal Java string manipulators to find the first instance of ":" and then get everything up to there.  But I want to be able to use regex because I have more complex constructs that I want to be able to use regex with. Ie being able to use RegEx is important.  Don't get hung up on the simplicity of my example above

 

What is the syntax I should be using please?

Thanks


Accepted Solutions
Sixteen Stars TRF
Sixteen Stars

Re: Using RegEx in tMap

From my understanding, you want to get the left part of row1.columname before ":". Right?
The simplest regex in this case is row1.columname.replaceAll(":.*$", "")
This method works for most cases as soon as you get the expression to represent what you want to remove.
String.split() may also be really usefull in many cases.
Home this helps.

TRF

View solution in original post

Tags (1)

All Replies
Sixteen Stars TRF
Sixteen Stars

Re: Using RegEx in tMap

From my understanding, you want to get the left part of row1.columname before ":". Right?
The simplest regex in this case is row1.columname.replaceAll(":.*$", "")
This method works for most cases as soon as you get the expression to represent what you want to remove.
String.split() may also be really usefull in many cases.
Home this helps.

TRF

View solution in original post

Tags (1)
Five Stars kdv
Five Stars

Re: Using RegEx in tMap

Thanks, that worked.  My regex wasn't working before.  But your solution does the trick.  Cheers!

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog