0

I've been trying to retrieve both, attributes' names, and values using Regex, tried different suggestions and none of it worked for me, whether it gets the first attribute, or nothing at all.

I am trying to use this regex to retrieve parameters passed via underscore customized include method

<% include attr1="value1" attr2="value2" %>

What I need is to get both of these parameters, ex. :

"attr1" : "value1"
"attr2" : "value2"

Thanks in advance

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Vald
  • 11
  • 1
  • are you using any js library or you are using core javascript? check the following question may be it wil help you https://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element-with-javascript-jquery – Amit Jun 25 '18 at 11:24
  • I am using core javascript, as mentioned I am trying to implement this regex to be able to pass parameters to the include method, which isn't natively supported by underscore, the solution you proposed won't work as I am willing to run the regex again't a string – Vald Jun 25 '18 at 11:30
  • Please post your effort – Saleem Jun 25 '18 at 12:19
  • @Saleem Sorry, here's an example on regex101 : https://regex101.com/r/BcueTd/1 what I need to do is to export all attributes, no matter how many they are – Vald Jun 25 '18 at 13:56
  • I'll suggest to process in two passes. In first pass, capture string between valid `<#... %>` tags and in second pass, capture k,v where **k** is attribute and **v** is value – Saleem Jun 25 '18 at 15:45
  • Yes I've already tried it that way and it worked, and I've come to see if there's any better solutions, logically it's possible with regex, I just didn't succeed on my own :( – Vald Jun 26 '18 at 09:58

0 Answers0