Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find words in string and add double quotes to it

Posted on 2011-03-16
3
Medium Priority
?
375 Views
Last Modified: 2012-06-27
Hi Experts,

I wonder if this is possible.

I have a string that looks like so: '{series:block1,singletonLoad:null}'

and I need to make it look like so;- {"series":"block1","singletonLoad":"null"}

how do i achieve the desired result using regular expressions please.

Thank you
0
Comment
Question by:claracruz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 1000 total points
ID: 35150932
<script>
var a =  '{series:block1,singletonLoad:null}';
alert(a)

a = a.replace(/([^\{\}\,\:]+)/g,"\"$1\"")
alert(a)
</script>

Open in new window

0
 
LVL 14

Expert Comment

by:sentner
ID: 35150984
Depends on the regex version you're using, but this should work with perl's engine:

s/(\w+)/\"$1\"/g
0
 
LVL 6

Expert Comment

by:ramelong
ID: 35153962
for a generic one similar to the previous (@senter), but more compatible:
a = a.replace(/([a-zA-Z0-9]+)/g,'"$1"');
alert(a);

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question