*this
home about contact feed
projects
vagra vaBlo
categories
C++(7) Solaris(4) tntnet(3) vi(3) Linux(2) DeleGate(2) Postgres(2) proxy(2) cxxtools(1) regex(1) readline(1) dtrace(1) gcc(1) MeeGo(1) ssh(1) firefox(1)

Easy to use regex in C++

cxxtools regex

cxxtools contains a nice class that allows you to use regular expressions in C++. Since it is so handy and not very documented, i like to show an short example.

#include <string>
#include <cxxtools/regex.h>

bool TwoFour (const std::string& word)
{
        cxxtools::Regex checkTwoFour("^[aA-zZ]{2,4}$");
        return checkTwoFour.match(word);
}

The function will return true only if word is between 2 and 4 characters long and consist only of alphabetic characters. Of course you can use more compley regular expression.

Write comment