Overview
Features
Download
Documentation
Community
Add-Ons & Services

Regular Expression Strange Behaviour

A general discussion forum.

Regular Expression Strange Behaviour

Postby nellute » 05 Jul 2011, 14:52

Hi, All,

I have found this strange behaviour

Code: Select all
int main(int argc, char* argv[])
{
    std::string value_tmp = "123456789";
    if (Poco::RegularExpression("[0-9]*").match(value_tmp) == true)
    {
        std::cout << "match" << std::endl;
    }

    return 0;
}


The above codes runs fine, it prints out the string "match".

However, if the string value_tmp contains a ' at the end, it does not match.

Code: Select all
"123456789'"


Any idea ?

BTW, I fell in love with Poco recently.
nellute
 
Posts: 4
Joined: 05 Jul 2011, 14:41

Re: Regular Expression Strange Behaviour

Postby nellute » 06 Jul 2011, 02:42

Sorry for the confusion.

I found out the answer.

Code: Select all
Poco::RegularExpression("[0-9]*").match(value_tmp)


is really matching the entire string against the pattern.

What I was looking for is to match a substring. The following will work for me.


Code: Select all
Poco::RegularExpression::Match match;

Poco::RegularExpression("[0-9]*").match(value_tmp, match)

nellute
 
Posts: 4
Joined: 05 Jul 2011, 14:41


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron