Jay Taylor's notes
back to listing indexHow do I retrieve all matches for a regular expression in JavaScript?
[web search]
I am new to regular expressions. I'm trying to parse the following kind of string:
where there are arbitrary key:"val" pairs inside. I want to grab the key name and the value. For those curious I'm trying to parse the database format of task warrior. Here is my test string:
But
|
|||||||||||||||
|
|||||||||||||||
Continue calling
Try it with this jsfiddle: http://jsfiddle.net/7yS2V/
|
|||||||||||||||||||||||||||||||||
|
This is a solution
This is based on lawnsea's answer, but shorter. Notice that the `g' flag must be set to move the internal pointer forward across invocations.
|
||||
Based on Agus's function, but I prefer return just the match values:
|
|||
Here is my function to get the matches :
|
|||
To loop within a string, you can fake a replace:
|
||||
Your Answer
asked |
4 years ago |
viewed |
15158 times |
active |
Linked
Related
Technology | Life / Arts | Culture / Recreation | Science | Other | ||
---|---|---|---|---|---|---|