Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
kdv
Contributor
Contributor

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

Labels (3)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

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.

View solution in original post

2 Replies
TRF
Champion II
Champion II

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.
kdv
Contributor
Contributor
Author

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