|
Boost Users : |
From: Arne Babnik (boost_at_[hidden])
Date: 2008-01-04 18:55:02
Hello,
I'm using boost::regex 1.34.0 and experience behaviour with mixed
greedy and non-greedy operators in the same expression which I do not
understand.
I have either one of the following input strings:
user1_at_[hidden]
user2
and want to keep only the usernames, so I use the following expression:
(.*?)(@.*)?
with the format string $1.
I would expect that basically the regex machine would first try to
satisfy the greedy operator "?", and then fill up the non-greedy "*?"
with the remaing part of the input.
However, the following does NOT work (the hostname is not removed):
std::string output;
output = boost::regex_replace(std::string("user1_at_[hidden]"),
boost::regex("(.*?)(@.*)?"),
std::string("$1"),
boost::regex_constants::format_first_only);
However, if I omit the "format_first_only", it works as expected.
What do I miss?
Thanks,
Arne
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
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