REGEX Lookbehind

Five Stars

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.


Accepted Solutions
Forteen Stars TRF
Forteen Stars

Re: REGEX Lookbehind

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

All Replies
Seven Stars

Re: REGEX Lookbehind

Why not substring?

String s = "myvalue:42";
System.out.println(s.substring(s.indexOf(":") + 1));
Five Stars

Re: REGEX Lookbehind

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?

Five Stars

Re: REGEX Lookbehind

bump

Forteen Stars TRF
Forteen Stars

Re: REGEX Lookbehind

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
Forteen Stars TRF
Forteen Stars

Re: REGEX Lookbehind

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

TRF
Five Stars

Re: REGEX Lookbehind

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. 


 

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

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