Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regular Expressions with VS2008

Last post 03-18-2009, 1:32 PM by travis. 2 replies.
Sort Posts: Previous Next
  •  03-16-2009, 9:49 PM 51562

    Regular Expressions with VS2008

    I was wondering if anyone here is familiar with regular expressions using Microsoft VS2008 (SP1)?  It's from the feature pack with TR1 regex.

    The function that I'm interested in is:
    std::tr1::regex_search

    http://msdn.microsoft.com/en-us/library/bb982334.aspx


    What I'm trying to do is search an entire file for a pattern match.  Such as:

     std::ifstream infile;
     infile.open( filepath );

     std::tr1::smatch result;
     const std::tr1::regex pattern( "(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+" );

     bool br = std::tr1::regex_search( ... ); // ???

     infile.close();

    But the arguments to regex_search() are somewhat confusing.

    regex_search() works fine with strings, but I was hoping I could just send it the entire file instead.
    Any idea how I would set this up?

  •  03-18-2009, 1:00 AM 51587 in reply to 51562

    Re: Regular Expressions with VS2008

    If the pattern you have provided works for a string, then all you should need to do is to read the entire file into a string and pass that to the regex.

    It looks like you are searching for email addresses (something a regex is typically NOT good at doing by the way - my work email would fail to match your pattern for example because it has multiple periods in it) as assuming that they cannot be split over multiple lines, then you should not need any special options (e.g. singleline or multiline).

    Therefore, an alternative would be to write your own function to read a line from the file, pass it to your regex and check for a successful match.

    If this is failing in some way, can you tell us the error message(s)?

    On the other hand if this is a question about what arguments you need to pass to the function, then I don't know if this is necessarily the right forum to ask. (Looking at the template definitions that you references, this is the reason why I consider C++ and templates to be a bad joke that got way out of hand!!!!!!)

    Susan 

  •  03-18-2009, 1:32 PM 51604 in reply to 51587

    Re: Regular Expressions with VS2008

    Thanks for the reply.  This is just a question about the parameters to regex_search().
    The docs aren't very helpful.  Templates are confusing.

    But I am able to do it line by line, which works ok.

View as RSS news feed in XML