J
J
Junior0072016-11-14 15:41:43
C++ / C#
Junior007, 2016-11-14 15:41:43

Regex regular expressions - how to do it right?

Let's say I have a line like this:

std::string str = "<html><body><a href=\"url\">name link</a><a href=\"url\">name link</a></body></html>";

How to get the contents of a link using regular expressions?
There seems to be no problem with the regular expression itself:
std::string str = "(.*)(<a href=\">)(\\w*)(<\/a>)";

But is it possible in C++ to get the contents of a link? Those. position in a string, for example.
In php, for example, this is possible.
Or for such purposes it is necessary to use std::string::find?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romy4, 2016-11-14
@Junior007

And if there is
<a lang="fr" href="url"></a>
then what?
and in the regular expression (\\w*) it will not catch your "name link" ;)
so there are problems with the regular expression

P
Pavel Belyaev, 2016-11-14
@PavelBelyaev

(<a href=[^>]+>)([^<]*)(<\/a>)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question