Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
lmit
Creator II
Creator II

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

Labels (2)
1 Solution

Accepted Solutions
lmit
Creator II
Creator II
Author

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

 

 

View solution in original post

7 Replies
ashif2
Creator II
Creator II

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.. 

TRF
Champion II
Champion II

Hi,

 

Here it is:

0683p000009LrD4.png

You can copy/paste the regex from here:

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

Hope this helps.

lmit
Creator II
Creator II
Author

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,

Lmit

lmit
Creator II
Creator II
Author

Thanks TRF for your reply 

TRF
Champion II
Champion II

Complete with this:

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

We can do this with one replaceall 

 

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

lmit
Creator II
Creator II
Author

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