Javascript regex ends with pattern -
i'm trying write regex in javascript identify string representations of arbitrary javascript functions found in json, ie.
{ "key": "function() { homecoming 'i function'; }" }
it's easy plenty identify start, can't figure out how identify ending double quotes since function might contain escaped double quotes. best seek far is
/"\s*function\(.*\)[^"]*/g
which works nicely if there no double quotes in function string. end of json key value end double quote , subsequent comma or closing bracket. there way retrieve characters (including newline?) until negated pattern such
not "/s*, , not "/s*}
... or need take different approach without regex?
here's current test info i'm working with: http://regexr.com/39pvi
seems want this,
"\s*function\(.*\)(?:\\.|[^\\"])*
it matches inbetween \"
escaped double quotes.
demo
javascript regex
No comments:
Post a Comment