Regular Expression in Java tMap

One Star

Regular Expression in Java tMap

Hello All,
I am looking for a way to use Regular Expression inside tMap, so that I can use parse my log file which has schema which is dynamic
--loc=us --tool=env --binary=/i686-pc-linux2.4/bin/env
--loc=us --binary=/i686-pc-linux2.4/bin/rm --tool=rm
--binary=/i686-pc-linux2.4/bin/grep --loc=us --tool=grep
--loc=us --tool=mv
I tried to understand how to extract text using Regular Expression inside java tMap expression editor. How can I call "--loc=(.+?) " inside tMap considering I have the log defined as delimitedfile.
Thanks in advance for your help.
Regards,
Sathish
One Star

Re: Regular Expression in Java tMap

Based on the following post, I should be created custom routine it seems.
http://www.talendforge.org/forum/viewtopic.php?id=10320
One Star

Re: Regular Expression in Java tMap

Hello All,
I had to write the following routine
package routines;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyRegExp {
public static String loc(String str) {
Pattern p = Pattern.compile("(?-m)--loc=(.+?)(\\s|$)");
Matcher m = p.matcher(str);
if (m.find()) {
return m.group(1);
} else {
return null;
}
}

public static String tool(String str) {
Pattern p = Pattern.compile("(?-m)--tool=(.+?)(\\s|$)");
Matcher m = p.matcher(str);
if (m.find()) {
return m.group(1);
} else {
return null;
}
}
public static String binary(String str) {
Pattern p = Pattern.compile("(?-m)--binary=(.+?)(\\s|$)");
Matcher m = p.matcher(str);
if (m.find()) {
return m.group(1);
} else {
return null;
}
}
}

Please let me know if know a better way.
Regards,
Sathish
Seven Stars

Re: Regular Expression in Java tMap

You could do it directly in a tMap expression but your way is, I think, better e.g.
row1.columnName.matches("(^|.*\\s)--foo=+(\\s.*|$)")?row1.columnName.replaceAll("(^|.*\\s)--foo=(+)(\\s.*|$)","$2"):null
One Star

Re: Regular Expression in Java tMap

Je vous laisse découvrir un aperçu du reportage et de cette séance photo de couple, et je remercie encore Antonina et Aurélien pour leur sympathie et Boutique de mariage en ligne la grande confiance qu?ils m?ont accordé !
Le loft à Coubevoie - 24, rue Pierre Brossolette 92250 robemariageonline.com La Garenne Colombes/ Courbevoie - www.leloft.fr/Leloft/leloft-location-accueil.html
Les bonnes adresses du mariage :