Regex on Server Side

Hi in a recent(ish) thread I was looking for a way to extract an ID and I received great help on how to do it here Extract an ID using regex. However, something that I really needed was for there to be regex server side. Is it possible to add in regex on the server-side rather than just on the app connect? Having Regex on the server-side enables us to ensure the data is in the correct format and not susceptible to data manipulation client side that could break certain features etc.

Thanks

That will be very important to me where I have used server side regex alot in my Bubble app…

Am I right in saying I can still write my own server side regex in php?

Best wishes,
Antony.

1 Like

What are you actually doing with all those regular expressions server side?

One example would be parsing of emails with inline/embedded images.

Microsoft Graph APIs separate the images into a separate API call. after getting all related images, you then need to replace all CIDs with image URL.

<img src='cid:<imagename>'/>

This is something that should happen on server side as new emails are received.

Hi @George… the two main uses off the top of my head are:

  1. Stripping out data returned by API calls such as Stripe to find specific information to feed back to the user.

  2. I have a massive booking form with potentially 10-100 user defined questions, where all the information entered by the user is captured client side in arrays of encoded text in order to prevent the form being slowed down by constant database access. Once the client completes the form, the array of encoded text is processed server side, where lots of regex is used to extract the relevent information and build the database structures that represent and store the results.

I don’t mind dropping down to some php code to do the regex, but the more you can do via the graphical Wappler interface the better… and certainly on Bubble you can do regex as standard in client and server side workflows.

Best wishes,
Antony.

I think you’ll find that those were workarounds rather than best practice. Database access is much faster than in bubble. And even if you want to hold off on the db, you have much better methods for temp storage like session and local browser storage.

3 Likes

I also think that’s some kind of workaround used in bubble.
@Antony can you provide a specific example of where/in what situations exactly you needed to use regex? Most probably it’s possible in server connect out of the box, using the server data formatters.

1 Like

I assume this is a hard thing to implement in server connect due to the various models you are / will be supporting?

Well, we first need to understand what’s the purpose of integrating such a feature, when you already have the data formatters.

1 Like

My opening example is a case where the formatters did not work unfortunately. The client side regex works beautifully it’s just replicating that server side. I assume there was a reason Regex was implemented client side as well?

There is absolutely no need to use regexp with Stripe for the server side. You just pick the data visually from the data picker.

With the formatters that we have you can do all the filtering you need as Teodor said.

For data validation we have all the validators at your disposal so there is also no need for regexp there.

@datguru regular expressions server side are indeed very difficult to implement because of their different native implementation in each server model. But we also never had the real need to use them because of the above.

Regexp are very difficult to use and very error prone and hard to debug, so we rather not use them when we have all the natural tools listed above. In comparison to them regexps feel like a dirty hack.

1 Like

I agree in principal however when you have the need to extract data from complex data (and even not so complex data) you can do that much more efficiently with regex. For example in the youtube ID example that I used in the initial opening post to do that I would need to create two functions to with the split and still would not be getting the same power or flexibility I get with regex. Not to mention there are so many patterns and so much help out there already that regex can become pretty much a copy and past affair for many situations to extract the correct data. I would argue that having multiple functions / bits of code to extract data becomes far more complex and error prone than using 1 line of regex.

I guess a workaround in the meantime would be to call an API for a PHP script that can pass back the regex’d data.

I can create a tutorial on how to create custom formatters and actions in Server Connect. Only problem is that Wappler will not recognize the custom code so that you can’t use the UI to update it.

5 Likes

That sounds like a great compromise patrick thank you

Hi Patrick, have you already created this tutorial? If so, where can I find it?

I have no tutorial yet, but replied in several topics how to create a custom formatter in PHP.

for example:

1 Like

I wanted to add some server-side validation, using regex, and then thought this is not possible - because regex isn’t available in server connect. But of course it is - but just for validation. It made me think of this thread. Presumably the difference in the various server models has been addressed in this case, for validation. Strange. Anyway, it would be a very useful feature if it can be useful generally in server connect.

1 Like

Bump! :slight_smile:

See this