Regular Expression using regex_search

This is a discussion on Regular Expression using regex_search within the C++ Programming forums, part of the General Programming Boards category; I search the board using "Regular Expression" and regex_search as keywords. I get "Sorry - no matches. Please try some ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    90

    Regular Expression using regex_search

    I search the board using "Regular Expression" and regex_search as keywords. I get "Sorry - no matches. Please try some different terms."

    Anyway, I'm trying to get the output below using regex_search only. I'm playing it by ear because all I read seems to take me out the regex_search function. For instance out of all the great things I learned here, he cut it off right here:

    These leaves us with:
    Replace any * characters with .*
    Replace any ? characters with .
    Leave square brackets as they are.
    Replace any characters which are metacharacters with a backslashified version.

    Code:
    #include <iostream>
    #include <string>
    #include <boost/regex.hpp>
    using namespace std;
    
    
    int main()
    {
       boost::regex expression( ""x*\.o"" );
    
       string string1 = "How to re";
    
       boost::smatch match;
    
       while ( boost::regex_search( string1, match, expression,
          boost::match_not_dot_newline ) )
       {
          cout << match << endl;
          string1 = match.suffix();    } }

    Code:
    //  Output needed:   oH to tore

    After over 30 hours of trying I found nothing that show me how to move back to the beginning to grab the {T} or how to store it for farther use. All of this and hundreds more ... after 30 hours, I still stuck. All I ask is how to move backwards or what do I have to do to get the first word in my result list in that order. I got enough below and more to take care of the rest I think.

    Thanks in advance.


    Code:
    //	boost::regex expression( "(\w)\o" );   // back reference DON'T WORK
    //   boost::regex expression( "[A-Z][a-zA-Z]*" );   // match first word, no symbols.
    //   boost::regex expression( "[A-Z][A-Za-z]*" );   // same as above
    //   boost::regex expression( "[a-zA-Z]+" );   // match all words and char only.
    //   boost::regex expression( "[^a-zA-Z0-9]+" );   // match symbols only.
    //   boost::regex expression( "[*.jpg]" );   // match word
    //   boost::regex expression( "[*.jpg]+" );   // with + inc any matching char
    //   boost::regex expression( "*.[ch]pp" );   // DON'T WORK FOR BOOST
    //	boost::regex expression( "[^B]" );   // don't find this char or sequence
    //	boost::regex expression( "[*B]" );   // Find all
    //	boost::regex expression( "B+" );   // find one or more
    //	boost::regex expression( "[a-z]+://" );   // get the header https://
    //	boost::regex expression( "yM?" );   // must find more than one char of one
    //	boost::regex expression( "{1}y" );   // match one DON'T WORK
    //	boost::regex expression( "( "( ?B)+" );   // will only get 4 char
    //	boost::regex expression( "( "( ?B)+" )";  // will only get 4 char
    //	boost::regex expression( "[ ?Bith]+" );   // find any of these
    //	boost::regex expression( "( ?ho)+" );   // whole word per line sequence
    //	boost::regex expression( "cow(ard|age|boy|l)?" );   // connect parts
    
    
    //	boost::regex expression( "^(\\D{2})" );   // get 5 char - (d) digit
    // [^\5]
    // [^(\k<1>)]
    // [^${1}]
    //	boost::regex expression( "(\\D+)(\\s*)(cow|M(M)?)" );   // back up and M to M
    	//boost::regex expression( "[^M]+(y+ig)?[big(igbay|age|boy|l)?]?+(ho|M(y)?)" );   // works great
    //	boost::regex expression( "^(\\D{2})+(\\D{2}) " );   // don't find this char or sequence
    //	boost::regex expression( ".*\.o" );   // copy all o
    //	boost::regex expression( "x*\.o" );   // copy only first o
    ... but I still read nothing about:

    These leaves us with:
    Replace any * characters with .*
    Replace any ? characters with .
    Leave square brackets as they are.
    Replace any characters which are metacharacters with a backslashified version.
    Regular Expressions Tutorial

    ... boost::regex_search for what I'm trying to do.

    flat assembler - View topic - Feature Request: Regular Expressions

    Regular Expression Matching Can Be Simple And Fast

    Benchmark of Regex Libraries

    Qt 4.7: QRegExp Class Reference

    Regular expression - Wikipedia, the free encyclopedia

    Perl Regular Expression Syntax - Boost 1.43.0 ... now things are getting easier. It's a new way to do your abc's ... That took me until Junior High ... heehee


    PS: After posting this thread now I see 4 links to Regular Expression below but 9 out of 10 they are not related. Going to read them now.

    The new forum look is very nice and it feels smooth
    Last edited by sharris; 04-12-2011 at 10:39 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The "This leaves us with" part is just instructions on how to translation a shell glob to a regular expression. Other than that, I'm afraid I don't understand your question.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    Thanks for the answer about shell glob. That article is the best you will ever find that has clear working examples to get one started, the right way.

    All I ask is how to move backwards or what do I have to do to get the first word in my result list in that order.
    I thought this was a very simple and fair question. Will I ever learn how to craft an question and include the words "PLEASE SAVE ME"! something that can be clearly understood.

    Anyway I found my answer in the boost link I posted above. This is new technology for C++ so you wouldn't know anyway. But the real answer is to study PURE-PERL Regular Expression and PERL examples ... than if you have to translate, you can only pray that it work for boost. Not all common PERL expressions will works between:
    Code:
     /^\ .... $/
    ... on boost. There no simple or complicated example in the documentation for this one. I think that all developer use to do that for proof of concept, once upon a time, when examples was not consider evil. I already experience the strange behavior that everyone will be taking about someday. It's good that it remains experimental for a little while longer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. regular expression
    By ashaikh432 in forum C++ Programming
    Replies: 2
    Last Post: 09-24-2010, 06:40 AM
  2. Regular Expression
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 09-02-2008, 02:15 PM
  3. Regular Expression
    By stevesmithx in forum C Programming
    Replies: 0
    Last Post: 02-18-2008, 10:00 AM
  4. regular expression
    By jackel7777 in forum C Programming
    Replies: 4
    Last Post: 08-16-2007, 03:02 AM
  5. Regular Expression..
    By vasanth in forum Tech Board
    Replies: 3
    Last Post: 08-03-2004, 07:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21