regular expression add double quotes around values and keys in javascript

前端 未结 4 1078
醉话见心
醉话见心 2020-12-21 04:05

i need a valid JSON format to request ES. i have a string like

{ 
time:  { 
          from:now-60d,
          mode:quick,
          to:now } 
}
4条回答
  •  盖世英雄少女心
    2020-12-21 04:22

    Good day Idriss

    if you wanted to place quotes around all the valid key names and values The maybe look at this expression. YCF_L's answer is prefect to what you wanted. But here it is none the less.

    {(?=[a-z])|[a-z](?=:)|:(?=[a-z])|[a-z](?=,)|,(?=[a-z])|[a-z](?=})
    str.replace(/{(?=[a-z])|[a-z](?=:)|:(?=[a-z])|[a-z](?=,)|,(?=[a-z])|[a-z](?
    =})/igm, $&");
    

提交回复
热议问题