Extract an ID using regex

Hello I was wondering if its possible to extract an ID from a URL in wappler. I want to extract the youtubeID for instance https://www.youtube.com/watch?v=jlS6NdfdaQ7z2rw what I would like to do is then extract jlS6NdfdaQ7z2rw. Is this possible?


should be able to extract it via the .split() function, splitting it on the “=” ?

Thanks where would I do the split sorry I am still very new to this in php I would be fine its just getting used to the way Wappler does it visually :slight_smile:

  1. Add a Text Input
  2. Add a Paragraph

The structure should look similar to:

  1. Click on Paragraph -> Dynamic Attributes plus icon

  2. Choose Display -> Inner Text

  3. Select the lightning bolt

  4. Under Data Bindings select value

  5. Click on the Data Formatter button

  6. In Data Formats right-click test1.value -> Manipulation -> Split

  7. Indata Formats choose Character and under the Parameter Properties type v=

This gives us an array of two strings, a string to the left of v= and a string to the right of v=, both strings separated by a comma. What we need to do is grab the second string.

  1. In Data Formats right click Split and choose Array -> Last

  2. In Data Formats choose Count and under Parameter Properties enter 1 (or true) for Count and choose Select

  3. In Data Bindings choose Select

  4. Save your document. The code should be similar to

That’s it. Test it in the browser.


Hi @datguru,
Where is the URL coming from? Are you entering it manually somewhere on your page, or is it some kind of dynamic data coming from a database?

Thanks @ben thats really useful would this be safe server side as well or is there a way to truncate the text serverside?

@Teodor the URL is being entered into a text box but I will then save the ID to a database to run various tasks on it


Ok, so is Ben’s solution what you are trying to achieve?

Yes Bens solutions will work, but I am thinking isnt it possible for someone to inject a post and it bypass the split if we are just using client side code?

You can format the $_POST variable (i.e. your form input) value on the server side, in your server action - directly in the insert record step. There is a server data formatter available:

Thanks Teodor, is there a list of expression functions or is this just pure PHP I can put in there?

Not sure what do you mean? There is a list of different formatting options just as Ben’s screenshots show.

I haven’t got access to the Wappler software at the moment but will check later on this afternoon. But I dont think when you click the magic wand it brings up the data formats that you get in Ben’s example? So I was wondering do you have a list of functions i.e like .split() that can be used in the expression?

It does exactly that :slight_smile:

1 Like

Thanks so much Teodor, apologies still a newbie! Thats exactly what I needed :smiley:

I’m not sure who to mark as the solution as its a combination of Ben & Teodor!

1 Like

Sorry Teodor… me again :D… So Split works perfectly for that usecase however the URL could come in a few different ways since its youtube it seems as though it doesn’t always have the = there. I have found a bit of regex that would work brilliantly to extract the ID but I dont see a pattern match option is there one for extracting using regex a bit like phps preg_match?

Just wondering @Teodor what the chance of getting an extract using regex is. You allow regex for validation why not for extracting into groups? It would make the data manipulation so powerful :slight_smile: