Hello boosters, First, apologies if this has been discussed before - I did some googling and could not find it. I've bumped into an interesting issue while using Boost.Regex. The documentation states: http://www.boost.org/libs/regex/doc/basic_regex.html Effects: Constructs an object of class basic_regex. The postconditions of this function are indicated in the table: Element Value empty() true size() 0 str() basic_string<charT>() Using 1.33, I get empty() set to false with the default constructor. In addition, if you attempt to search using an empty regex, the program segfaults. The following example demonstrates the problem: code: ------ #include <iostream> #include <string> #include <boost/regex.hpp> int main() { std::string line("this is an example line"); boost::smatch what; boost::regex re; std::cout << "re.empty(): " << re.empty() << std::endl; bool result = boost::regex_search(line, what, re); } output: ------ re.empty(): 0 Segmentation fault This does not happen if I initialize the regex using an empty string (it throws empty expression). Which leads to the main question (and the reason why I discovered all of this): is it possible to make a regular expression that matches anything? For instance, when using AWK, if you define a rule without a pattern, i.e.: { print $0; } I thought an empty regex would do the trick. Regards, Marco -- in software development, the design document is a source code listing. -- jack reeves
Using 1.33, I get empty() set to false with the default constructor. In addition, if you attempt to search using an empty regex, the program segfaults. The following example demonstrates the problem:
Yes, it's a bug that will be fixed in 1.33.1 when it arrives.
This does not happen if I initialize the regex using an empty string (it throws empty expression). Which leads to the main question (and the reason why I discovered all of this): is it possible to make a regular expression that matches anything? For instance, when using AWK, if you define a rule without a pattern, i.e.:
I thought an empty regex would do the trick.
An empty regex has always been an error in Boost.Regex (because I couldn't think of a legitimate use for it). Use (?:) for an empty expression, You can also use these if you really want an empty alternative: "|abc" is not a valid expression (usually user error), but "(?:)|abc" does the same thing, as does: "(?:abc)??" . HTH, John.
participants (2)
-
John Maddock
-
Marco Craveiro