boost::regex_replace for complete dummies

Discussion in 'C++' started by oxkfame@gmail.com, May 7, 2009.

  1. Guest

    This is the first time that I ever needed to use regex from C++, and
    while boost has the library, I am at a complete loss. What am I doing
    wrong?
    cout << boost::regex_replace(string("[^]"),
    boost::regex("\(\[\)\(\.\*\)\(\]\)"),
    string("$2")) << endl;

    Shouldn't it print ^ ?

    I realize that I am missing something in my knowledge, I just wish I
    knew what.

    Thank you in advance.
    , May 7, 2009
    #1
    1. Advertising

  2. Guest

    > Start by writing the regular expression, just as you'd type it into a
    > text editor:
    >
    >         \[(.*)\]
    >
    > Then turn it into a quoted string, escaping the backslashes:
    >
    >         "\\[(.*)\\]"
    >
    > (written but not tested).
    >
    > --
    >    Pete
    > Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
    > "The Standard C++ Library Extensions: a Tutorial and Reference"
    > (www.petebecker.com/tr1book)


    You rock. I get it now, and it absolutely worked like expected.

    Thank you SO much.
    , May 7, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    1,835
  2. Replies:
    6
    Views:
    394
    Robbie Hatley
    Jul 14, 2006
  3. Yahooooooooo

    boost::regex_replace compiler error

    Yahooooooooo, Jan 22, 2007, in forum: C++
    Replies:
    3
    Views:
    458
  4. Yahooooooooo

    boost::regex_replace issue

    Yahooooooooo, Jan 30, 2007, in forum: C++
    Replies:
    1
    Views:
    1,329
    David Harmon
    Jan 31, 2007
  5. Friedel Jantzen

    regex_replace()

    Friedel Jantzen, May 10, 2011, in forum: C++
    Replies:
    16
    Views:
    1,387
    James Kanze
    May 15, 2011
Loading...

Share This Page