Boost logo

Boost Users :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-03-20 12:33:50


John Maddock wrote:
> skywalker Luke wrote:
>> Hi All,
>>
>> I'm developing my own grep tool and I would like to specify an
>> option to match a whole word. Which mean, if I'm looking for 'main' I
>> don't want to match 'mainVariation' but things like 'main(int' or
>> 'one,main,two'. The equivalent of what you will find in any decent
>> search tool :).
>>
>> I look through regex documentation and didn't find anything about
>> that. If it's not implemented, is it planned to be ? Or shall the
>> Boost.Regex user handle this applying some pre-processing on the
>> regular expression to perform such task ?
>
> Correct, there's no compile time flag to alter this, but you can encase your
> regex in \<(?:expression)\> where "expression" is your original expression.

<aside>
Had you been using xpressive, you could do this as follows:

   sregex rex = ... make a regex object ... ;

   // make rex "whole word" by wrapping it in begin-
   // and end-of-word assertions
   rex = bow >> rex >> eow;

Although munging the regex string like John suggests works, too.
</aside>

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net