473,386 Members | 1,819 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,386 software developers and data experts.

regExp pattern

Hello

I am trying to read an aicc ini.file and storing each section and its
content into a new Object{}

[section]
prop1=value1
prop2=value2
prop3=value3
prop4=value4

[section2]
....
....

Would someone out there knows javaScript regExp and could give me one or two
hints on how to write a regex pattern?

Thanks a lot for your help

Roland
Oct 27 '05 #1
1 1168
JRS: In article <43**********@news.tiscalinet.ch>, dated Thu, 27 Oct
2005 21:39:48, seen in news:comp.lang.javascript, Roland <in**@gmm.ch>
posted :
Hello

I am trying to read an aicc ini.file and storing each section and its
content into a new Object{}

[section]
prop1=value1
prop2=value2
prop3=value3
prop4=value4

[section2]
...
...

Would someone out there knows javaScript regExp and could give me one or two
hints on how to write a regex pattern?


ISTM that a single RegExp, if possible, would be unduly complex.
<HEAD></HEAD><BODY><script>

S =
"[section0]\n" +
"prop1=value1\n" +
"prop2=value2\n" +
"\n" +
"[sectionA]\n" +
"propb=valueb\n" +
"propc=valuec\n"

S = S.replace(/\[(\w+)\]/g, " }, $1: {")
S = S.replace(/(\w+)=(\w+)/g, " $1:'$2',")
S = S.replace(/,\s+}, /g, "},\n\n ")
S = S.replace(/^\s+},/, "Obj = {")
S = S.replace(/,\s+$/, "} } ;\n")

document.write("<pre>",S) // which writes the following Object

Obj = { section0: { prop1:'value1', prop2:'value2'},
sectionA: { propb:'valueb', propc:'valuec'} } ;

</script></BODY></HTML>

To test, put that as a page and execute locally. To understand, comment
out all replace lines, and unveil in turn. Then adapt.

Not necessarily optimal.
*** DO NOT MULTIPOST ***

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 28 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bosconian | last post by:
Using preg_replace() is there a simple regexp to strip everything from a string except alpha and numeric chars (a-zA-Z0-9)? $input = "$tring1!"; $pattern = $input = preg_replace($pattern, "",...
1
by: python_charmer2000 | last post by:
I want to match several regexps against a large body of text. What I have so far is similar to this: re1 = <some regexp> re2 = <some regexp> re3 = <some regexp> big_re = re.compile(re1 +...
3
by: Jane Doe | last post by:
Hello, I need to browse a list of hyperlinks, each followed by an author, and remove the links only for certain authors. 1. I searched the archives on Google, but didn't find how to tell the...
5
by: Ronald Fischer | last post by:
I have a server-side JavaScript function returning a string. I would like to test wheather or not the string contains the following pattern: - an equal sign, - followed by one or more characters...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
6
by: Edward | last post by:
I need to validate a text box entry, but ONLY if it is 17 characters, otherwise I have to ignore it. My regular expression for the validation is: ^(({9})()()(\d{6}))$ Can I adapt this to...
6
by: micklee74 | last post by:
hi i created a script to ask user for an input that can be a pattern right now, i use re to compile that pattern pat = re.compile(r"%s" %(userinput) ) #userinput is passed from command line...
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
2
by: gypsy3001 | last post by:
Today, I was trying to construct a regular express in JavaScript. But I kept getting the "Error: unterminated parenthetical" message. I want to do something like this: keyCombo = ":(";...
2
by: Nathan Sokalski | last post by:
I have the following script that I am using to test some JavaScript RegExp code: function RE() { var testing1=new RegExp("*"); var testing2=new RegExp("{0,}"); var testing3=new RegExp("+");...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.