-1

I have problems with a regexp pattern. I'm using the non-greedy .*? but it seems it is greedy, too? Can you help me, please?

myString:

myString = '{"testname":"mytest","type":{"aaa111":{"url":"http://www.test01.com"},"222bbb":{"url":"http://www.test02.com"},"ccc333":{"url":"http://www.test03.com"}}}';

myPattern:

/"(.*?)":{"url"/g

The result:

testname":"mytest","type":{"aaa111, http://www.test01.com"},"222bbb, http://www.test02.com"},"ccc333

But the result "should" be:

aaa111, 222bbb, ccc333 

1 Answers1

0

One way around this is to make sure it doesn't match multiple " (double quotes)

"([^"]+?)":{"url

https://regex101.com/r/oU6eX4/1

Though I agree with the other comments that there are probably better solutions that don't involve regex.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118