Monday, February 22, 2010

Installing the Boost regex library on Ubuntu linux OS (+tutorial sites on how to use it)

For any of you C++ fans out there, I've been spending HOURS trying to get Boost regex to work on my system (a library used for handling C++ regular expressions). Well I finally did. And I'm going to tell you how. Just so you know, I use the command-line to compile my programs, so if you use something that is more GUI-oriented, I'm not sure if I can help.

Step 1 - go into your synaptic package manager.

Step 2 - type "boost regex" into the search field option and hit search.

Step 3 - choose a boost library package from the list (I chose libboost-regex1.40-dev).

Step 4 - click the checkbox next to it and then hit the "mark for installation" option.

Step 5 - click apply (somewhere along the line, it should tell you it needs to install other libraries in order to install hit, obviously, you should allow it to do so)

here's a test program that I wrote and then the command-line I used (in the command-line compile, it's VERY important to put the -lboost_regex part at the end)

(WARNING: I'm an idiot and haven't learned how to write a "<" character with a a-z character following it properly so the HTML formatting doesn't treat my include statements like tags yet, so add the appropriate file names from the comment below the # include statements) //This program utilizes the match function to check the format of a string
#include <>
#include <>
#include <>

/* the inside of your include statements should be iostream, string, boost/regex.hpp, respectively */
using namespace std;

int main(int argc, char * argv[]){
boost::regex re("a*");
boost::cmatch matches;
string hi = "aaa";
if(boost::regex_match(hi.c_str(), matches, re)){
cout << "it works " << endl;

Syntax tutorial:

Usage tutorial (pages 3-4 were really useful for me):

No comments:

Post a Comment