02-14-2019 06:01 AM - edited 03-15-2019 06:45 AM
Can we use regular expressions in the string.replace method? For example:
strCallingNumber.replace("/'[+]?[9]?[+]?[1]?(\d{3})?(\d{3})(\d{4})|([135]\d{4})$/","$1-$2-$3$4")
This doesn't seem to do it, I tried without the quotes as well...
Solved! Go to Solution.
02-14-2019 12:25 PM
string.replaceAll(pattern as string,replacement as string) does not want the slashes on the regular expression pattern. The following gives me what I want, or at least expected
strTelNumber.replaceAll("[+]?[9]?[+]?[1]?(\d{3})?(\d{3})(\d{4})|([135]\d{4})$","$1-$2-$3$4")
02-14-2019 07:10 AM
With this we would not be able to define what is your goal
can you explain, what is your input and what you expect to replace ?
or just use this website give you so many combinations to test
02-14-2019 08:24 AM
To reformat a string to phone number. External calls come in as 918881231234 and internal as 3XXXX
I want external to be formatted as 888-123-1234 and internal to remain as is 31234
Thats actually the site I used to build the expression and it works as far as I can tell
02-14-2019 12:25 PM
string.replaceAll(pattern as string,replacement as string) does not want the slashes on the regular expression pattern. The following gives me what I want, or at least expected
strTelNumber.replaceAll("[+]?[9]?[+]?[1]?(\d{3})?(\d{3})(\d{4})|([135]\d{4})$","$1-$2-$3$4")
02-14-2019 08:04 AM
02-14-2019 08:32 AM
strCallingNumber.replaceAll("/[+]?[9]?[+]?[1]?(\d{3})?(\d{3})(\d{4})|([135]\d{4})$/","$1-$2-$3$4")
Input 918882223333
Desired output 888-222-3333
Input 31111
Desired output 31111
Am I going about this wrong?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide