From Thursday, July, 9, 3:00 PM Pacific,
our Community site will be in
read-only mode
through Sunday, July 12th.
Thank you for your patience.

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
Highlighted
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}
Highlighted
One Star

Re: regex replace - backreference

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

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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog