Jump to content

[C++] boost::regex - searching

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
winuser

winuser

    Newbie

  • Members
  • PipPip
  • 26 posts
Hello, im trying to search string, example:

<some tags>asf</some tags><span class="power">120kW</span><some tags>assd</some tags><spac class="power">400kW</span>

with use of boost::regex lib - regex_search
i want to separate each <span class="power"> value (120 or 400..) into std::vector.

Can help me anynone with this ?
Thanks

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Have you figured out the regex to match the power span, or are you needing help with how to put it in a loop to get all the power spans? Or is the issue with std::vector?

What code do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
winuser

winuser

    Newbie

  • Members
  • PipPip
  • 26 posts
Hmm, i have problem with loop, i wrote simple code:


	boost::regex re("(<span class=\"power\">)..kW(</span>)");

	boost::smatch what;

	if(boost::regex_search(c, what, re))

	{

		std::cout << what[0];

	}

How to use this in loop ?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I don't think you're approaching it correctly. After you find it, you will need to reduce your string to what's left and re-search.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog