473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Need help with javascript regular expression

I have a javascript utility and need so help with regular expressions..

Basically I have lines of data that consists of name=value pairs delimited with commas.

example
match=type abc{0,4}D,search=(.*?) (.*?) (.*),replace=$2 $1 $3

The problem I have is sometimes as in the example a value may have a comma in it. In these cases in the value will be with a quoting mechinism,
That include "value", 'value', (value), [value], and {value}.

I need a way to replace the commas inside the quote mechinism with something else so the split of the name value pairs works properly.

After the split I need to restore the commans in the values that had them.

Any assistance would be greatly appreciated.
Jul 18 '07 #1
1 1295
mrhoo
428 256MB
You can use a regular expression.exec(string) to loop through the lines and match single and double quotes and their contents. Replace any quote enclosed commas with a \t (tab) or other character you won't use in a value,
and replace the tabs after the split.

You have to watch out for escaped quotes and apostrophes, and be sure to match single or double quotes only with themselves.

It would be best to replace the commas on the input side, or use another delimeter.
Jul 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: MJ | last post by:
I'm having problems coming up with a regular expression that works for what I want. I need to extract a few numbers from from html. Here's a snippet: <tr><td align="right">Consolidated Metro...
12
by: Smash | last post by:
i have this function: ------------------------------------------------------------ function isAlfaNumeric(vnos,space) { if (space==false) { validRegExp = /^{0,}$/; } else { validRegExp =...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
6
by: Friso Wiskerke | last post by:
Hi All, I'm trying to find a way to validate a string variable in the code behind with a regular expression. I know there are validator controls but these all work with the ControlToValidate...
6
by: GHUM | last post by:
I need to split a text at every ; (Semikolon), but not at semikolons which are "escaped" within a pair of $$ or $_$ signs. My guess was that something along this should happen withing csv.py;...
9
by: lev | last post by:
Attempting to use javascript's regular expression methods to match a particular lab number and building which would then be copied to a pair of textfields, I found that general matching characters...
8
by: frohlinger | last post by:
Hi, I have a search textbox in my website. I validate the search string with a "white list" of allowed characters: if((/^+$/).test(theSearchWord) == false) { return; }
3
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.