2

I have a string:

<tag1 qwer=123>Hello</tag1>

And I want a regex that will have a single match for its inner content:

Hello

Using the following code:

string s = "<tag1>Hello</tag1>";
smatch sm;
regex re("<tag1>([\\s\\S]*?)</tag1>");
regex_match(s, sm, re);

I get one match and one its submatch:

<tag1>Hello</tag1>
Hello

What regex should I use to get simply one match:

Hello

Thanks!

Artem
  • 159
  • 2
  • 14

1 Answers1

2

This works for valid single-line XML tags:

regex re("[<][^>]+[>]([^<]+)[<]\/[^>]+[>]");
l33t
  • 18,692
  • 16
  • 103
  • 180