Solved

Find words in string and add double quotes to it

Posted on 2011-03-16
3
372 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 250 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript object functions help 1 19
Javascript Regex 7 20
Html using "Or" in condition 3 27
Looking for solution to pass data to 3rd-party web platform? 4 30
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

726 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