rajat
rajat

Reputation: 3553

JavaScript error invalid quantifier

This javascript code:

var regex = /(?<=<img src=").*?(?=")/gm;
var src = regex.match(str); 

Gives me this error:

SyntaxError: invalid quantifier ?<=<img src=").*?(?=")
    in eval() line 0

What is the problem?

Upvotes: 1

Views: 2784

Answers (2)

MicronXD
MicronXD

Reputation: 2220

You need to escape your question marks like so:

/(\?<=<img src=").*?(\?=")/gm

EDIT:

The above fixes your "invalid quantifier" problem. But, as @Pointy points out in his comment, RegExp objects contain no match function. You're likely looking for match on a string. (e.g., "string".match(/reg(exp)/);).

Upvotes: 2

kushalbhaktajoshi
kushalbhaktajoshi

Reputation: 4678

Take a look at match() format

var src = str.match(/(?<=<img src=").*?(?=")/gm);

Upvotes: 1

Related Questions