-1

I was wondering how it's possible (if it is) to get multiple elements between text.

For example my test String is <pizza>name:1;John:2</pizza>Carl:8and I want to get all the Names:number that are between the <pizza> tags.

If I use \w+:\d I get name:1, John:2 but also Carl:8.

Is there a way to get only the ones inside the tags? (So only name:1 and John:2 in this case)

I've tried using <pizza>(\w+:\d;)+</pizza> but it only gives me the last one that's inside.

Thanks in advance!

Neïl Rahmouni
  • 326
  • 2
  • 10

1 Answers1

0

This should do:

(?<=<pizza>).*?(?=</pizza>)

Positive lookbehind

(?<=<pizza>)

Matches the actual value you want to extract

.*?

Positive lookahead

(?=</pizza>)
TobyU
  • 3,718
  • 2
  • 21
  • 32