JavaScript How to regex everything between colon and space? regex everything between two characters,regex everything between two strings,

I have this string

product_id:WDC WD2500YS-18S revision:6C07 size(GB):232 state: ONLINE

and I need convert to anything else, like json:

{
  "product_id": "WDC WD2500YS-18S",
  "revision": "6C07",
  "size(GB)": "232",
  "state": "ONLINE"
}

I tried this /([^:]+)/g, but is not working because I need that the WD2500YS-18S be togetter with WDC WD2500YS-18S.

Answer:1

You must use the fact that the key doesn't contains spaces and check what follows with a lookahead.

/([^\s:]+):\s*([^:]+?)(?=\s+[^\s:]+:|\s*$)/g
Answer:2

This solution doesn't rely on lookaheads or lookbehinds, and utilizes the browser's built-in json parser to verify that the output is valid. It leverages the fact that the keys do not contain spaces. So ([^ ]+): will find a key. We just wrap the key and value with quotation marks and let the built-in json parser do the rest.

var input = 'product_id:WDC WD2500YS-18S revision:6C07 size(GB):232 state: ONLINE';
console.log(JSON.parse(
  '{' +
  input.replace(/(^| )([^ ]+):/g,'","$2":"').substring(2) +
  '"}'
));

outputs:

{
product_id: "WDC WD2500YS-18S",
revision: "6C07",
size(GB): "232",
state: " ONLINE"
} 
Answer:3

So, I have an <img> tag that has an onclick attribute. The onclick calls a function called analyze(this), with this being the image. The analyze function does some things to the image that ...

So, I have an <img> tag that has an onclick attribute. The onclick calls a function called analyze(this), with this being the image. The analyze function does some things to the image that ...

  1. capture onclick event javascript
  2. capture onclick event jquery
  3. onclick capture event
  4. canvas capture onclick event
  5. html onclick capture event
  6. capture click event onclick
  7. capture click events

how to change the color of a line in a HTML page(text in a pre>) Containing A specifique word for example i want to change the color a any line containig "ERROR" and "Erreur" 2014/05/22 02:27:02 - X....

how to change the color of a line in a HTML page(text in a pre>) Containing A specifique word for example i want to change the color a any line containig "ERROR" and "Erreur" 2014/05/22 02:27:02 - X....

  1. change color line plot matlab
  2. change color line matplotlib
  3. change color line edittext android
  4. change color line autocad
  5. change color in photoshop
  6. change color line chart ggplot
  7. change color line chart excel
  8. change color line procreate
  9. change color line in photoshop
  10. change color line illustrator
  11. change color line between columns word
  12. change color line graph illustrator
  13. change color line ggplot
  14. change color line sketchup
  15. change color line textinputlayout
  16. change color line ggplot2
  17. change color line gnuplot
  18. change color line plot python
  19. change color line highcharts
  20. change color line graph matlab

I have the following User object: { "_id" : ObjectId("someId"), "name" : "Bob", "password" : "fakePassword", "follower" : [...], "following" : [..] } I need to paginate over the follower ...

I have the following User object: { "_id" : ObjectId("someId"), "name" : "Bob", "password" : "fakePassword", "follower" : [...], "following" : [..] } I need to paginate over the follower ...

  1. mongodb limit fields returned
  2. mongodb limit fields
  3. mongodb find limit fields
  4. mongodb lookup limit fields
  5. mongodb aggregate limit fields
  6. mongodb query limit fields
  7. spring data mongodb limit fields

I am working through a project for a company I plan on working for and I was given a code challenge to create a choropleth map of Kenya. I have been able to generate the map using GeoJSON and TopoJSON ...

I am working through a project for a company I plan on working for and I was given a code challenge to create a choropleth map of Kenya. I have been able to generate the map using GeoJSON and TopoJSON ...