2005-04-11

boost regex!

I posted on the PLUG mailing list about regex libraries in C/C++. Matt Baluyos pointed me at PCRE and paolo falcone pointed me at Boost. I decided to go with boost because I couldn't stand the PCRE library.

That's not to denigrate the quality of the library, it works, very well. I use PCRE implicitly in PHP and it's a great help and is incredibly easy to use there. But C is now just too low level for me and while I can work there, I don't like it much. If I can, I work in PHP (perl is far too ugly for me, although that could change if i were to work in it instead of just reading it). I'll be working in java soon, but I tend to have a bias against it for small projects. I'm sure it's great for large projects, but even there, the libraries and frameworks seem over-engineered. But that's probably just a function of the fact that they're large enough that I can't get my brain around them in a week.

For anything lower level that I can't do in java or php, i like C++. And that's where I use the boost regex libraries. I've written utility functions that hide some of the details of the boost implementation (just pass string pattern, string data, vectormatches, and internally it does everything else). there's also a similar set of utility functions that passes the pattern as a regex const reference instead (so that patterns that are used all the time aren't re-compiled).

it's very nice to be able to say:

vector matches;

if ( re_search(pat, line, matches) )
{
for (int ctr=0; ctr < matches.size(); ctr++)
do_something_with_match(matches[ctr]);
}

No comments: