Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

REGEX Lookbehind

I am using a regex, 

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

to match a number after "myvalue:", the data looks like "myvalue:42", and I need the 42. This works in most regex engines, but I'm having trouble getting it to match in Talend. Please advise.

Labels (2)
6 Replies
Anonymous
Not applicable
Author

Why not substring?

String s = "myvalue:42";
System.out.println(s.substring(s.indexOf(":") + 1));
Anonymous
Not applicable
Author

Thank you for the reply; love the avatar. 

 

So you are suggesting I use something like

(myvalue:[0-9]*)

then use a tJavasomething to substring it?

Anonymous
Not applicable
Author

bump

TRF
Champion II
Champion II

This one should also work:

row1.myField.replaceAll("^.*:", "")

and if you expect the result as an Integer:

Integer.parseInt(row1.myField.replaceAll("^.*:", ""))

This may appear in a tMap expression or in any place where you're able to enter a piece of Java code.

Hope this helps. 

TRF
Champion II
Champion II

Did this help you?
If so, thank's to mark your case as solved (Kudo also accepted).
Anonymous
Not applicable
Author

Hi @TRF, thank you for the suggestion. I will test and get back to you.


@TRFwrote:

This one should also work:

row1.myField.replaceAll("^.*:", "")

and if you expect the result as an Integer:

Integer.parseInt(row1.myField.replaceAll("^.*:", ""))

This may appear in a tMap expression or in any place where you're able to enter a piece of Java code.

Hope this helps.