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
Not the answer you're looking for? Browse other questions tagged javascript regex or ask your own question.
asked |
4 years ago |
viewed |
15158 times |
active |
Linked
Related
Hot Network Questions
- What was the original process for becoming a US citizen?
- Have Elrond and Galadriel ever spoken to each other in person?
- Set math mode as default for each item in list
- Any way to save a large tree that's starting to split/crack down the middle?
- What is this gesture called in English?
- Is there a Batman-Lovecraft connection?
- Why is it considered safe to install something as a non-root user in Linux environments?
- The Unicode look of disapproval no longer displays correctly in 16.04 - how do I fix this?
- Constrain Locator to specified region
- Como conjugar verbos que exprimem fenômenos da natureza?
- Polygonal numbers
- What is a word for a condition one is born with?
- How can we be sure that computers will never accidentally switch a 0 by a 1?
- Why is text justified in newspapers, but not on the web?
- "Page intentionally left blank" article
- Sum line lengths for each grid cell in QGIS
- Are units of angle really dimensionless?
- Are the beast shape weapon attacks of a Druid, simple or finesse?
- How did Obi-Wan survive the trip to Naboo?
- What Level of Government Debt to GDP Ratio is Sustainable?
- Tikz: failure to fill
- Why does CO2 accept electrons?
- Do I need a comma or semi-colon before particularly in this example
- STM32F4 : Floating point instructions too slow
Technology | Life / Arts | Culture / Recreation | Science | Other | ||
---|---|---|---|---|---|---|