827
Views
4
Comments
Solved
Get only numbers from string
Question
Application Type
Service

Hello, I have a string that can take numbers simbols etc... For example:

1231asdnk123-.as1

and I want to take only the numbers like this

12311231

I know that we can use regex to come to this. 

The thing is, that it seems that all regex i make in RegEx_Search only returns the first pattern that comes... In this case the return would be 1231, but I need to join them all

UserImage.jpg
Francisco Calderón
Solution

Hi Ricardo,

You can use the Regex_Replace action from the Text API (Text Extension) to fulfill your goal:

What it does is replace every non-digit character with the empty string, thus leaving you with only the numeric symbols.

Hope it helps!

2021-12-29 03-29-46
Ricardo Figueiredo

This was perfect! I was using Regex_Search, but this is exacly what I needed.
Thanks for the help!  :)

2018-10-29 08-31-03
João Marques
 
MVP

Hi Ricardo,


You have the Regex How-To forge component which not only allows to play with regex in its sandbox, it also provides a few common scenarios like the one you mention.


You just need to do remove all that is different than a number, or replace it by nothing, like in the example above.


Kind Regards,
João

2021-11-30 12-35-05
Ricardo Ferreira

Hi Ricardo,

You can use the method .replace method like in the image below:

Hope it helps,

Best regards,

Ricardo


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.