Replace letters a-z with blank space or count just the digits


In the Server Action I am trying to set a value in my action to remove the letters in a strong (a-z) and replace them with empty space.
Essentially I am just trying to count only digits in a string. So I thought I would first remove the letters a-z and then use Word Count to count the digit remaining.
I can’t get this to work.
Whats the best way to do this.

For example the string ‘Wappler 2022’, I would want to strip/remove all the alphabet letters and leave only 2022 and then count 2022.

What server model are you using?

I am using PHP

You can use a custom formatter for this.
Create the following folder in your site root: extensions/server_connect/formatters
Inside this folder create a file called strings.php with the following content inside it:

namespace lib\core;

function formatter_count_numbers($str) {
  $numbers = preg_replace('/\D/', '', $str);
  return strlen($numbers);

then you can use it like this in Server Connect steps:


Screenshot 2022-08-02 at 14.15.34

and it will return the count of the digits. Example:
my_value = “abc123-456-cde”


will return: 6

1 Like

I am doing this on Server App side as I will be using it in mySQL query.

This is a server side formatter, used in Server Connect.

1 Like

Yes it is indeed. Thanks @Teodor I will give this ago. Exactly what I am trying to achieve.
Wondering if its something that can be added into Wappler?

We can’t add every single use case as a formatter in Wappler :slight_smile: One will want to count numbers, others letters and some others may want to calculate the distance to the sun.
That’s why you can use the custom formatters easily the way i explained above, for any non-standard use case - it’s really easy.

that’s true! and yes it is really easy. Although distance to Mars maybe a good one :slight_smile: :laughing: