CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    144

    Performing RegEx on open file

    Hi, like the title says, I'm trying to open a file and perform a regex on it, then print the matches, but I'm not sure if I have it right. I think I need to remove the line -
    Code:
    [for ( std::vector<TCHAR>::iterator It = buffer.begin();It != buffer.end(); It++ )
    since I've already copied the file into the buffer, but how do I search the buffer?

    Code:
    std::ifstream in(TempFullPath, std::ios::in|std::ios::binary);
    
    if( in.fail() )
    {
    	std::cout << "File does not exist or could not open file";
    }
    
    
    std::vector<TCHAR> buffer;
    std::copy( 
    		std::istreambuf_iterator<TCHAR>( in ),
    		std::istreambuf_iterator<TCHAR>(),
    		std::back_inserter( buffer )
    		);
    for ( std::vector<TCHAR>::iterator It = buffer.begin();It != buffer.end(); It++ ) {
    	sbuf = (*It);
    	if( boost::regex_search(sbuf , matches, re ) )
    			{
    				std::string value( matches[1].first, matches[1].second );
    				StringCchCat(TextAreaBuffer, MAX_PATH, value.c_str());
    				StringCchCat(TextAreaBuffer, MAX_PATH, TEXT("\r\n"));
    				int ndx = GetWindowTextLength (textArea);
    				SetFocus (textArea);
    				#ifdef WIN32
    					SendMessage (textArea, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
    				#else
    					SendMessage (textArea, EM_SETSEL, 0, MAKELONG (ndx, ndx));
    				#endif
    					SendMessage (textArea, EM_REPLACESEL, 0, (LPARAM) (TextAreaBuffer));
    						
    		}
    }
    Last edited by drwbns; January 11th, 2013 at 12:45 PM.

  2. #2
    Join Date
    Mar 2011
    Posts
    144

    Re: Performing RegEx on open file

    I found a better way of how to open a file. But I need help trying to match a url using boost::xpressive. I got the following off the web that doesn't match anything, other examples I tried throw a compile error. Does anyone know of a boost compatible regex to match a URI? I tried to match using this but I'm not sure if I'm escaping correctly -
    Code:
    sregex::compile("(\?:ftp\|https\?:\/\/)\+(\?:\\S+\.)\+(\?:\\S\.)\+(\?:\S)\+");
    Last edited by drwbns; January 12th, 2013 at 03:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured