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.
Hi @George… the two main uses off the top of my head are:
Stripping out data returned by API calls such as Stripe to find specific information to feed back to the user.
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.
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.
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.
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.
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.
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.