How to use REGEX in tJava(row,flex)

Highlighted
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
Highlighted
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..!

View solution in original post


All Replies
Highlighted
Ten Stars

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

tExtractRegexFields should support any regex supported by Java's Pattern class.
Highlighted
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. 

Highlighted
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

Highlighted
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.

Highlighted
Five Stars

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

bump

Highlighted
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..!

View solution in original post

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

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog