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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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?

 

Labels (1)
  • v7.x

6 Replies
cterenzi
Specialist
Specialist

tExtractRegexFields should support any regex supported by Java's Pattern class.
Anonymous
Not applicable
Author

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. 


regex_match.PNG
Anonymous
Not applicable
Author

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.

0683p000009LwPb.png0683p000009LwhA.png

Anonymous
Not applicable
Author

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.

Anonymous
Not applicable
Author

bump

crt1
Contributor
Contributor

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:

0683p000009LvIE.jpg 

Hope this helps..!