Boost.Regex - Match whole word
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 ? Thank you. LS ----------------------------------------------------------- www.EmailAsso.net : solutions email pour les associations, email gratuit sans pub ni virus. www.lavacheautomatique.com : email gratuit @lavache.com, original et universel. www.MonEmail.com : l'email professionnel à 1Giga, avec agenda partagé et gestion des contacts. Votre bureau vous suit partout. 30 jours d'essai gratuit.
Hi LS, I think you should consult regex syntax first. There are many possibilities to do so. One of them is (\w)* means greedy match of as many words as possible. There are some regex tutorials on the internet, google for them. Boost.Regex is a lib which supports the syntax of different regex specifications (Perl, POSIX ...) With Kind Regards, Ovanes -----Original Message----- From: skywalker Luke [mailto:skywal_l@lavache.com] Sent: Dienstag, 20. März 2007 08:23 To: boost-users@lists.boost.org Subject: [Boost-users] Boost.Regex - Match whole word 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 ? Thank you. LS ----------------------------------------------------------- www.EmailAsso.net : solutions email pour les associations, email gratuit sans pub ni virus. www.lavacheautomatique.com : email gratuit @lavache.com, original et universel. www.MonEmail.com : l'email professionnel à 1Giga, avec agenda partagé et gestion des contacts. Votre bureau vous suit partout. 30 jours d'essai gratuit. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
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. John.
John Maddock
Correct, there's no compile time flag to alter this, but you can encase your regex in \<(?:expression)\> where "expression" is your original expression.
John.
It's exactly what I was looking for, thank for your quick and precise answer, and yes, I could have find out by myself, sorry. LS
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
Eric Niebler
<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>
Hi Eric, Sorry I didn't know xpressive. Actually I don't find it in the Boost documentation... You may want to add something in http://www.boost.org/libs/libraries.htm. As for me, it's my entry point to Boost documentation... Thanks for your help.
Skywalker Luke wrote:
Sorry I didn't know xpressive. Actually I don't find it in the Boost documentation... You may want to add something in http://www.boost.org/libs/libraries.htm. As for me, it's my entry point to Boost documentation...
It wasn't in the last boost release, but it will be in the next one. For now, it's in the vault (http://boost-consulting.com/vault/index.php?directory=Strings%20-%20Text%20P...) and the documentation is at http://boost-sandbox.sf.net/libs/xpressive/. -- Eric Niebler Boost Consulting www.boost-consulting.com
Eric Niebler
It wasn't in the last boost release, but it will be in the next one. For now, it's in the vault
(http://boost-consulting.com/vault/index.php?directory=Strings%20-%20Text%20P...)
and the documentation is at http://boost-sandbox.sf.net/libs/xpressive/.
Ok, thanks again Eric, I'll have a look to this. Btw, do you know when 1.34.0 will be released? I can't find any roadmap on boost website.
participants (5)
-
Eric Niebler
-
John Maddock
-
Ovanes Markarian
-
skywalker Luke
-
Skywalker Luke