"CB" <bo*****@hotmail.com> writes:
Sorry I'm not explaining this well. I'm only referring to matching a
string. The string just happens to be code for a obj literal. The
object that the literal describes is not relevant.
var a = "{ '{' : 'LeftCurly', '}' : 'RightCurly' }";
var b = "{ '{' : 'A punctator', '}' : 'Another punctuator' }";
I'm looking for the RegEx that will match both the entire strings in
the variables a and b.
new RegExp(""); // :P
But seriously, you are only telling us half the specification by
saying that it must match these. We also need to know what it
shouldn't match.
Should it match strings that does not contain object literals?
Should it match strings containing any object literal, or only
those with single-quote delimited strings as key and value?
Should it match strings with objects literals with other than
two properties?
It's probably painfully obvious to you what you want (that's
when it's hardest to explain :), but try to explain in words,
concisely, what you want to match and what you don't.
An example matching only single-quote delimited strings as keys and
values, and any number of properties:
/^\{\s*('[^'\\]*(\\.[^'\\]*)*'\s*:\s*'[^'\\]*(\\.[^'\\]*)*'(\s*,\s*'[^'\\]*(\\.[^'\\]*)*'\s*:\s*'[^'\\]*(\\.[^'\\]*)*')*\s*)?\}/
Sometimes a single regular expression is *not* the way to go :)
Instead try writing a real parser.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'