i bit new regular expressions in javascript.
i trying write function called parseregexpression() parses attributes passed , generates key/value pairs works fine input:
"icontype:plus;iconposition:bottom;" but not able parse input:
"type:'date';locale:'en-us';" basically - sign being ignored. code at:
http://jsfiddle.net/visibleinvisibly/zss5g/
the regular expression key value pair below
/[a-z|a-z|-]*\s*:\s*[a-z|a-z|'|"|:|-|_|\/|\.|0-9]*\s*;|[a-z|a-z|-]*\s*:\s*[a-z|a-z|'|"|:|-|_|\/|\.|0-9]*\s*$/gi;
there few problems:
- a
|inside character class means literal|character, not alternation. - a
.inside character class means literal.character, there's no need escape it. - a
-first or last character inside character class means literal-character, otherwise means character range. - there's no need use
[a-za-z]when use case-insensitive modifier (i);[a-z]enough. - the difference between alterations last bit; can simplified limiting alternation part different.
this should equivalent original pattern:
/[a-z-]*\s*:\s*[a-z0-9'":_\/.-]*\s*(?:;|$)/gi
Comments
Post a Comment