regex replace - backreference

Highlighted
One Star

regex replace - backreference

Hey everybody,
I'm trying for hours (it feels so) to do a tReplace with a regular expression. The search pattern is fine, but what about the Replacement? How can I reference my search pattern? I tried almost everything: \1 @1 $1 with and without quotes.
Can anyone help me?
Thanks in advance
Shaddy
Employee

Re: regex replace - backreference

Let's take the following input file :
there are 4 cats and 1 dog
we have 1 horse and 2 chickens
10 birds 1 cat

On each line, we want to extract the 2 numeric values and concatenate them in reverse order.
In tReplace, Advanced Settings, Advanced Mode, the Pattern is : "^.*?(\\d+).*?(\\d+).*$" and the Replace is "$2;$1"
The output of the job is :
Starting job topic2991 at 22:32 29/05/2008.
1;4
2;1
1;10
22 milliseconds
Job topic2991 ended at 22:32 29/05/2008.

Employee

Re: regex replace - backreference

For those interested in the Perl solution of this problem, still in tReplace, Advanced Settings, Advanced mode, Regexp pattern is s{^.*?(\d+).*?(\d+).*$}{$2;$1}
One Star

Re: regex replace - backreference

Thanks a lot,
I really had a mistake in the search pattern.
Best Wishes
Shaddy

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch