-1

I've been struggling all day to try and convert the following regex that works for php, into a form for javascript. I am trying to use it for some VBA where I can replace "sedol" with a variable so I can loop through the string to get "name" and other elements So for example below I would want the outcome to = '0452173'

php regex:

(?<="sedol":")(.+?)(?=",")

String extract:

"sedol":"0452173","name":"Aberdeen Japan Equity (Class I)", .....
rp4
  • 1
  • 1

1 Answers1

0

The problem is that JS doesn't support look behind. However, you could do this:

var re = new RegExp("(?:\"" + yourVar + "\":\"(.+?)(?=\",\")");

Then use

var res = re.exec(yourString);
if (res != null) { // match
    return res[1]; // the matched part of (.+?)
}
Michael Schmidt
  • 110
  • 1
  • 14