
Hello all, I have the following regular expression, but it doesn't match to this text "REVENUE ................................................... $10,481.1" const char* pattern[] = "Revenue[\s\.]*\$?\s*([0-9,\.]*)"; my code looks something like this: std::vector <unsigned int> v; boost::RegEx expr(pattern, true); v.clear(); unsigned int result = expr.Grep(v, pBuf); if (result != 0) { std::string s = expr[0]; s = expr[1]; ............ Why expr[0] and expr[1] weren't return the aboved mention text as the first match? I think set 'true' in expr constructor means do case insensitve match. /Winson.

Winson Yung wrote:
Hello all, I have the following regular expression, but it doesn't match to this text "REVENUE ................................................... $10,481.1"
const char* pattern[] = "Revenue[\s\.]*\$?\s*([0-9,\.]*)";
Don't you need to double up those escapes? Remember that C++ consumes the first \ so you need \\ to pass an escape to the regex engine: const char* pattern[] = "Revenue[\\s\\.]*\\$?\\s*([0-9,\\.]*)"; HTH, John.

John, I had in the code. It's just when I wrote this in the email, I forgot
to double escape them.
Sorry about that, anyhow it still doesn't work with double escapes.
/Winson
On 7/22/06, John Maddock
Winson Yung wrote:
Hello all, I have the following regular expression, but it doesn't match to this text "REVENUE ................................................... $10,481.1"
const char* pattern[] = "Revenue[\s\.]*\$?\s*([0-9,\.]*)";
Don't you need to double up those escapes? Remember that C++ consumes the first \ so you need \\ to pass an escape to the regex engine:
const char* pattern[] = "Revenue[\\s\\.]*\\$?\\s*([0-9,\\.]*)";
HTH, John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Winson Yung wrote:
John, I had in the code. It's just when I wrote this in the email, I forgot to double escape them. Sorry about that, anyhow it still doesn't work with double escapes.
In that case I don't see an obvious mistake, can you provide a short test case demonstrating the problem? John.

Sure, here is the zip file contain the test code compiled under Visual C++ 6
as a console application. The code is bit of rough, but it behave the same
way as my app. I have included a raw.txt file. In the file, the pattern is
suppose to match line 2760, but instead it seems to me it's matching line
4907.
/Winson
On 7/22/06, John Maddock
Winson Yung wrote:
John, I had in the code. It's just when I wrote this in the email, I forgot to double escape them. Sorry about that, anyhow it still doesn't work with double escapes.
In that case I don't see an obvious mistake, can you provide a short test case demonstrating the problem?
John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Winson Yung wrote:
Sure, here is the zip file contain the test code compiled under Visual C++ 6 as a console application. The code is bit of rough, but it behave the same way as my app. I have included a raw.txt file. In the file, the pattern is suppose to match line 2760, but instead it seems to me it's matching line 4907.
OK I see the problem: when you sub-script the RegEx object you get the n'th sub-expression of the *last match found* in the last operation. If you dump the results in the vector you will see that a large number of matches were indeed found. You could pass a vectorstd::sting to Grep to get the actual strings that matched, or if you need more information then you'll have to use a callback function. Finally note that this is a legacy interface that is deprecated. There are now better alternatives, for example regex_iterator or regex_token_iterator. John.

Thanks John, I am using 1.28.0 version of regex library.
Is the regex_iterator and regex_token_iterator available in 1.28.0? Are they
better in turn of performance?
What's the reason Regex::Grep() and alike get deprecated?
/Winson
On 7/22/06, John Maddock
Winson Yung wrote:
Sure, here is the zip file contain the test code compiled under Visual C++ 6 as a console application. The code is bit of rough, but it behave the same way as my app. I have included a raw.txt file. In the file, the pattern is suppose to match line 2760, but instead it seems to me it's matching line 4907.
OK I see the problem: when you sub-script the RegEx object you get the n'th sub-expression of the *last match found* in the last operation. If you dump the results in the vector you will see that a large number of matches were indeed found. You could pass a vectorstd::sting to Grep to get the actual strings that matched, or if you need more information then you'll have to use a callback function.
Finally note that this is a legacy interface that is deprecated. There are now better alternatives, for example regex_iterator or regex_token_iterator.
John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Winson Yung wrote:
Thanks John, I am using 1.28.0 version of regex library. Is the regex_iterator and regex_token_iterator available in 1.28.0? Are they better in turn of performance? What's the reason Regex::Grep() and alike get deprecated?
Oh, no they were added in 1.31.0. The Regex class was always a bit "wrong headed" and not very good design, most people were using the templates directly anyway, and once these were accepted for standardisation there was no reason to continue supporting the old interface. There's no difference in performance between them, they all call the same routines internally. John.
participants (2)
-
John Maddock
-
Winson Yung