Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
krishu
Contributor II
Contributor II

String Handling

Hi Team

I have a requirement where the data is something like 010.040.103.222.1234.000 and the expected output should be

010.103.222.1234000. The basic idea is from the input i have to remove 5-8 characters (i.e, 040.) and in the last i.e. 20th position i have to remove '.'

input: 010.040.103.222.1234.000

expected output: 010.103.222.1234000

Any idea team! Appreciate your help.

Thanks & Regards

Krishu

Labels (5)
1 Solution

Accepted Solutions
gjeremy1617088143

ok first i replace a (dot followed by 1 to 3 digits) preceded by 1 to 3 digits a the bergining of the string (Lookbehind regex expression)

then i replace a dot followed by 1 to 3 digits a the end of the string (Lookahead regex expression)

https://www.regular-expressions.info/lookaround.html for more info about Lookbehind and Lookahead

 

^ is for begining of the string

$ is for end of he string

 

 

 

 

View solution in original post

4 Replies
gjeremy1617088143

HI , (your string).replaceAll("(?<=(^\\d{1,3}))(\\.\\d{1,3})","").replaceAll("\\.(?=\\d{1,3}$)","")

Send me Love and Kudos

krishu
Contributor II
Contributor II
Author

Hi gjeremy1617088143

 

Thank you soo much😉 it worked, but could you explain what exactly u have written in the logic. It looks like regex but I don't how regex works..

 

Thanks & Regards

Krishu

 

gjeremy1617088143

ok first i replace a (dot followed by 1 to 3 digits) preceded by 1 to 3 digits a the bergining of the string (Lookbehind regex expression)

then i replace a dot followed by 1 to 3 digits a the end of the string (Lookahead regex expression)

https://www.regular-expressions.info/lookaround.html for more info about Lookbehind and Lookahead

 

^ is for begining of the string

$ is for end of he string

 

 

 

 

krishu
Contributor II
Contributor II
Author

Thank you very much😀 😍