[SOLVED] REPLACE_PATTERN & Multiple Patterns

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

[SOLVED] REPLACE_PATTERN & Multiple Patterns

Post by PointsWell »

In my continuing hell of international telephone numbers and notation habits I am now trying to strip out all the crud that I have to allow people to add here

This means I have to remove ' ', '(', ')' and '-'.

It seems that you can't nest REPLACE_PATTERN so is there another way, other than multiple REPLACE_PATTERN to cover each of the different patterns?
Last edited by PointsWell on Tue May 29, 2018 7:19 am, edited 1 time in total.
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: REPLACE_PATTERN & Multiple Patterns

Post by Jaymer »

Sean
Do you want me to write you a Java function to remove those 4 characters?

Contact.Phone = PHONE_STRIP(Contact.Phone)

if so, supply me with the working regular expression that achieves what you need.

jaymer...
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: REPLACE_PATTERN & Multiple Patterns

Post by BobK »

PointsWell wrote: It seems that you can't nest REPLACE_PATTERN
What do you mean by that?
I have used something like the following:
BO.NewAttr = REPLACE_PATTERN(REPLACE_PATTERN(BO.OldAttr, 'find1', 'replace1'), 'find2', 'replace2')

You still need multiple REPLACE_PATTERN statements, but they are inside each other and I call that nested.


More to a solution to your problem:

If you need to remove all non-numeric characters, you only need 1 REPLACE_PATTERN like:

BO.JustNumbers = REPLACE_PATTERN(BO.AlphaNumeric, '[\D]', '')

\D matches any non-digit
Bob
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REPLACE_PATTERN & Multiple Patterns

Post by PointsWell »

BobK wrote: More to a solution to your problem:

If you need to remove all non-numeric characters, you only need 1 REPLACE_PATTERN like:

BO.JustNumbers = REPLACE_PATTERN(BO.AlphaNumeric, '[\D]', '')

\D matches any non-digit
It's little nuggets like this that make this forum such a powerful resource! And saves the very generous Jaymer from reinventing the wheel (though I was keen to have a peek inside the mystery that is Java to me). Now if only we could tag stuff in here better.
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: REPLACE_PATTERN & Multiple Patterns

Post by PointsWell »

BobK wrote:
PointsWell wrote: It seems that you can't nest REPLACE_PATTERN
What do you mean by that?
I have used something like the following:
BO.NewAttr = REPLACE_PATTERN(REPLACE_PATTERN(BO.OldAttr, 'find1', 'replace1'), 'find2', 'replace2')

You still need multiple REPLACE_PATTERN statements, but they are inside each other and I call that nested.
That was exactly what I was trying to achieve but it seems that one of the characters that I was trying to replace needed to be escaped - it was causing an error on the console.
Post Reply