How to use REGEX in tJava(row,flex)

Five Stars

How to use REGEX in tJava(row,flex)

I have hit a wall using tExtractRegexFields, namely positive lookahead, which does not appear to be in this list, so it appears I cannot use that component. Let's start simple. How would I use a simple regex to match something from a column in a tFileInputDelimited and cat it to a tLogRow?

 


Accepted Solutions
Five Stars

Re: How to use REGEX in tJava(row,flex)

It works fine with Pattern and Matcher within a tJavaRow component.

 

I used tRowGenerator to generate one row with your string:

 

blah () ; blah, {} words myvalue:42 more data [] 23

In the tJavaRow, aside from the input and output row code I used the following code as a very rough example:

 

Pattern pattern = Pattern.compile("(?<=myvalue:)[0-9]*");
Matcher matcher;

if (pattern.matcher(input_row.Test).find()){
	System.out.println("Row Matched");
}
else{ System.out.println("Row not Matched"); }

Which gave me the following result when I ran the job:

TOS_DI-win-x86_64_2018-04-23_16-42-41.jpg 

Hope this helps..!


All Replies
Ten Stars

Re: How to use REGEX in tJava(row,flex)

tExtractRegexFields should support any regex supported by Java's Pattern class.
Five Stars

Re: How to use REGEX in tJava(row,flex)

If I use 

(?<=myvalue:)[0-9]*

on data

blah () ; blah, {} words myvalue:42 more data [] 23

in jEdit or elsewhere, it matches "42". Talend is not giving me a match. 

Five Stars

Re: How to use REGEX in tJava(row,flex)

Also, if I attempt to match data inside brackets in Talend I am met with an "Invalid escape sequence.." error. This works elsewhere. Please see screenshots.

invalid_escape_seq.PNGset_match.PNG

Five Stars

Re: How to use REGEX in tJava(row,flex)

If it is known why these are not working any help would be appreciated. As per the OP, if it is known how to use REGEX in a tJavawhatever component, that information would be greatly appreciated.

Five Stars

Re: How to use REGEX in tJava(row,flex)

bump

Five Stars

Re: How to use REGEX in tJava(row,flex)

It works fine with Pattern and Matcher within a tJavaRow component.

 

I used tRowGenerator to generate one row with your string:

 

blah () ; blah, {} words myvalue:42 more data [] 23

In the tJavaRow, aside from the input and output row code I used the following code as a very rough example:

 

Pattern pattern = Pattern.compile("(?<=myvalue:)[0-9]*");
Matcher matcher;

if (pattern.matcher(input_row.Test).find()){
	System.out.println("Row Matched");
}
else{ System.out.println("Row not Matched"); }

Which gave me the following result when I ran the job:

TOS_DI-win-x86_64_2018-04-23_16-42-41.jpg 

Hope this helps..!

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads