javascript - Give priority to group inside regular expression -


i want output what's inside var data = "this";, i've manage this:

var plaintext = fs.readfilesync( process.argv[ 1 ] ).tostring(); var regex = new regexp("var\\ data\\ =\\ \"(.{0,})\";", "g", "y"); var regex2 = new regexp("\"(.{0,})\"", "g"); var info = json.parse(plaintext.match(regex)[0].match(regex2)[0]); 

is there way have 1 regular expression, , compact code 2 or 3 lines?

how this?

plaintext.match(/var\s+data\s*=\s*"(.*)";/)[1] 

update: regex match strings contain escaped quotes, e.g. "\"foo\"" long these quotes aren't followed semicolon. work, closing quote must followed semicolon.

as alternative, exclude double quotes matched string (use [^"]* instead of .*) , leave out semicolon regular expression.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -