Incognito has asked for the wisdom of the Perl Monks concerning the following question:
The following regular expression matches MOST object initializer regular expressions written in JavaScript.
qr{/(?:[^\\/]|\\.)*/[gi]*};
This basically matches the following JavaScript code:
var objRegex = /"/; var objRegex = /'/; var objRegex = /\\/; var objRegex = /123[abc]456/; var objRegex = /\\\\/; var objRegex = /te'st\/as"df/; var objRegex = /123[\/]456/;
BUT fails to match on a valid Regex like this:
where there is a single "/" character embedded in [] (this is apparently valid because most special characters do not have to be escaped inside [])... If the regex had the "/" character escaped, then this wouldn't be an issue.var objRegex = /123[/]456/;
Does anyone know how to improve the regex to match any valid JavaScript object intializer regular expression? (which seem pretty much identical to Perl regular expressions)?
Fixed disappearing square brackets 2002-02-14 dvergin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching an JavaScript object initalizer regex
by japhy (Canon) on Feb 14, 2002 at 04:13 UTC | |
by Incognito (Pilgrim) on Feb 14, 2002 at 19:53 UTC | |
by japhy (Canon) on Feb 15, 2002 at 00:10 UTC | |
by Incognito (Pilgrim) on Feb 15, 2002 at 00:36 UTC | |
|
Re: Matching an JavaScript object initalizer regex
by little (Curate) on Feb 14, 2002 at 03:50 UTC | |
by broquaint (Abbot) on Feb 14, 2002 at 17:53 UTC | |
by little (Curate) on Feb 14, 2002 at 18:15 UTC |