Regular Expression in Formatter

I need to extract some text posted by user. For that I need regex. Is there anyway to use regex in wappler?

It’s available as a validation both server side and client side. Screenshot is server side.

Here is a regex I use on forms for phone number formatting.

Can I use it to extract text? It seems validator only validates the data.

Yes, that only validates the data/entries. I am not really clear on what you are trying to do. Maybe post exactly the details of what you are trying to do and someone can help.

He wants to extract text that matches a certain regex - validation is checking if it exists, not extract

1 Like

It’s pretty easy to set up a custom formatter to do what you want. What server model are you using?

I’m using PHP/MySQL

Exactly

And it’s in a server action API you want to perform the regex? (Or client-side)

Server side

This was something I was after that I submitted a feature request for Regex on Server Side

Thank you pointing that out. Added my vote there.

btw, can it be done at client side? If yes, how?

There is an example of using built in features here Extract an ID using regex to split the text but you can’t use regex directly. That maybe possible with just running a custom javascript though?

That formatter can be used at server side action as well. Isn’t it?

There’s instructions for PHP formatters here:

Probably something like this:

<?php namespace lib\core; 
function formatter_regexreplace($str, $pattern){ 
$retval = preg_replace($pattern, '', $str);
return $retval; 
} ?>

You would then use it in a data binding code view as:

somevalue.regexreplace('thepattern')

e.g.
somevalue.regexreplace('([0-9])')

to remove digits

1 Like

If that is in relation to the post before. Yes you can use the formatters server side (see here link to Teodors reply on my post Extract an ID using regex) as well or use a custom one as @bpj has linked above.

1 Like