none
How to checking an regular expression in regex for boost library? RRS feed

  • Question

  • How to checking an regular expression in regex for boost library?

    If i input an error expression,the IDE will throw an error, but i can't catch it.Thanks for everyone.

    Sunday, November 7, 2010 6:22 PM

Answers

  • try {

        boost::regex reg("ErrorExpression[");

    } catch ( *I forget the type here, but it is documented in the boost library) {

        // error handling code here

    }

     

    That is the general way you catch a regular expression error.

    Sunday, November 7, 2010 9:26 PM
  •  

    Hi

     

    I just find out codes as SimonRev said:

     

    try
    {
      boost::regex re("(ftp|http|https):\/\/(\w+\.)*(\w*)\/([\w\d]+\/{0,1})+");
      if (!boost::regex_match(url, re))
      {
       throw "Your URL is not formatted correctly!";
      }
    }
    catch (boost::regex_error& e)
    {
      cerr << "The regexp " << re << " is invalid!" << endl;
      throw(e);
    }
    

    And here is error type of boost regex error_type.

     

    Hope my information can help you!

     

    Regards!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, November 9, 2010 4:49 AM
    Moderator

All replies

  • 源�?�?�代 <=?utf-8?B?5rqQ5aeL5pe25Luj?=>  wrote:

    How to checking an regular expression in regex for boost library?

    If i input an error expression,the IDE will throw an error, but i  can't catch it.Thanks for everyone.

    What  exactly is preventing you from catching the exception?


    Igor Tandetnik

    Sunday, November 7, 2010 8:11 PM
  • try {

        boost::regex reg("ErrorExpression[");

    } catch ( *I forget the type here, but it is documented in the boost library) {

        // error handling code here

    }

     

    That is the general way you catch a regular expression error.

    Sunday, November 7, 2010 9:26 PM
  •  

    Hi

     

    I just find out codes as SimonRev said:

     

    try
    {
      boost::regex re("(ftp|http|https):\/\/(\w+\.)*(\w*)\/([\w\d]+\/{0,1})+");
      if (!boost::regex_match(url, re))
      {
       throw "Your URL is not formatted correctly!";
      }
    }
    catch (boost::regex_error& e)
    {
      cerr << "The regexp " << re << " is invalid!" << endl;
      throw(e);
    }
    

    And here is error type of boost regex error_type.

     

    Hope my information can help you!

     

    Regards!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, November 9, 2010 4:49 AM
    Moderator
  •  

    Hi,

     

    I'm very interested your issue, did you solve your problem?

    If so please share the solution with us and mark the right answers.

    If not please let me know.

     

    Have a nice day!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, November 10, 2010 6:55 AM
    Moderator