Raj Raj - 4 months ago 15
Javascript Question

Positive look behind in JavaScript regular expression

I've a document from which I need to extract some data. Document contain strings like these

Text:"How secure is my information?"


I need to extract text which is in double quotes after the literal
Text:


How secure is my information?


How do I do this with regex in Javascript

Answer

JavaScript regular expressions do not support lookbehinds. You have to use capturing parenthesis instead:

var str = 'Text:"How secure is my information?"',
    reg = /Text:"([^"]+)"/;
alert(str.match(reg)[1]);
// -> How secure is my information?