Five Stars

Regex Expression in tmap

Hi All,

I have a input with special characters in a string, if i find special character the output should have data before special character

for example : Input file will be like below

data

------

abc-de

abcde+fg

 

Output file should be like

data

-----

abc

abcde

How can i achieve it,i tried with regexp but i couldn't get the correct..

What could be the regexp to handle all special characters in tmap or in routine also will be fine

 

Can anyone please suggest how can i achieve it.some help would be helpful for me as i have seen some posts but was not useful

 

Thanks in advance,

Lmit

7 REPLIES
Six Stars

Re: Regex Expression in tmap

public class HelloWorld{

public static void main(String []args){
System.out.println("Hello World");
String str="abc d +";
System.out.println(str.substring(0,str.replaceAll("[^a-zA-Z0-9]", "~").indexOf('~')));
}
}

 

 

Here is my approach,replace all non alphanumeric with '~', take the substring.. 

Eleven Stars TRF
Eleven Stars

Re: Regex Expression in tmap

Hi,

 

Here it is:

Capture.PNG

You can copy/paste the regex from here:

row10.code.replaceAll("[-+].*$", "")

Hope this helps.


TRF
Five Stars

Re: Regex Expression in tmap

Hi Ashifa,

 

Thanks for your quick reply , you code is working fine but i missed one more point thats is , 

input file

data

-----

P100078-9

 

If the data has alphabets , we should remove that also, i.e., my output should be

output file

data

---

100078

first we need to check in data whether its having special characters and alphabets, if so we need to remove alphabets and need populate the data which is before the special character.

 

Thanks a lot, it was very helpful.

 

Thanks in advance,

Amala

Five Stars

Re: Regex Expression in tmap

Thanks TRF for your reply 

Eleven Stars TRF
Eleven Stars

Re: Regex Expression in tmap

Complete with this:

row10.code.replaceAll("[-+].*$", "").replaceAll("[A-Z]", "")

TRF
Six Stars

Re: Regex Expression in tmap

We can do this with one replaceall 

 

str.replaceAll("[^0-9]", "")

Five Stars

Re: Regex Expression in tmap

Thanks Guys for your replies but both of your codes are removing the alphabets.below is the code

removechar.substring(0,removechar.replaceAll("[a-zA-Z]","").replaceAll("[^a-zA-Z0-9]", "~").indexOf('~'))

 

I tried with below codes

str.replaceAll("[^0-9]", "") & replaceAll("[A-Z]",""), i tried with changing positions also but couldn't success.

Its not showing error but the output is coming with alphabet.

 

Thanks In Advance,

Lmit