Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2004-12-31 10:26:55


> I'm new in regex and this is my first post, so maybe the solution is
> obvious
> but I couldn't find it in google...
>
> I need to parse the multiline output of a command, every line ends with a
> \n
> except the last one, which actually it ends with the end of buffe ("\0"
> character). The output I need to parse is something like:
>
> "text1 this is a multiple-word text\n
> text2 another text"
> (the second line does not have a newline)
>
> As a result I want only two sub-expression in a line using a regex like:
>
> (\w+)\s+([^\n]+)\n
>
> The first submatch should be the first word ("text1" and "text2"), while
> the
> second submatch would be the rest of the line ("this is a multiple-word
> text" and "another text")
>
> In my program I use regex_search with the boost::match_continuous option,
> all the other regex objects are created with the default options.

It depends whether you want to capture the newline character or not, if you
do then:

(\w+)\s+([^\n]+)(?:\n|$)

would do the trick, otherwise if you don't want the newline character (just
the contents of each whole line) then:

^(\w+)\s+([^\n]+)$

Used without the match_continuous flag would do it.

John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net