JohnOne Posted September 16, 2012 Share Posted September 16, 2012 VS 2010 has std::tr1::regex which resides in <regex> I was hoping this standard support would be similar to AutoIt3 stringregex, but I'm beginning to think otherwise now, but I'm hoping I'm wrong. Has anyone figured a way (if there is one) to get an array of all matches of a pattern with one call to regex_search() with a flag of some kind, or are multiple calls and iteration absolutely necessary? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Solution Mat Posted September 16, 2012 Solution Share Posted September 16, 2012 (edited) More accurately the C++11 standard includes a regex library. Have you looked at sregex_iterator?? Should mean only one call and then a for loop, but I have never actually used that library. Edited September 16, 2012 by Mat JohnOne 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
JohnOne Posted September 16, 2012 Author Share Posted September 16, 2012 I never new it was C++ 11, never thought VS2010 had that. Anyway, you are correct about std::sregex_iterator. I suppose it was just wishful thinking to hope for something as ace as StrngRegExp(). AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
danielkza Posted September 17, 2012 Share Posted September 17, 2012 (edited) An example for you (tested only on VS2012). It's not particularly complicated if you know C++ already, just a bit verbose, but that's usually the price for the good stuff in C++.#include <string> #include <iostream> #include <regex> int main(int argc, char **argv) { std::string data("a.b.c.d"); std::regex pattern("([^.])+(.|$)"); std::regex_iterator<std::string::iterator> it(data.begin(), data.end(), pattern); for(; it != decltype(it)(); ++it) { auto match = *it; if(!match.empty()) std::cout << match[1].str() << std::endl; } return 0; } Edited September 17, 2012 by danielkza JohnOne 1 Link to comment Share on other sites More sharing options...
Ascend4nt Posted October 3, 2012 Share Posted October 3, 2012 If you are using Windows XP+, or Win 2K w/IE 5.5, you can skip C++ regular expressions and use the Visual Basic RegExp library which is on every system post WinXP. There's a few articles about using it, but I decided to write my own C/C++ version. Here's two places you can look:http://www.codeproject.com/Articles/4594/Use-regular-expression-in-your-C-programhttp://www.codeproject.com/Articles/6274/Convenient-wrapper-of-VBScript-RegExp-for-VCNote that the VB RegExp library doesn't allow lookbehind assertions, just as Visual C++ doesn't. I'd instead recommend the same library that AutoIt uses, PCRE (http://www.pcre.org/).And just in case someone complains, I'll state the obvious here: the VB RegExp library is not portable to other O/S's, of course. JohnOne 1 My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 4, 2012 Share Posted October 4, 2012 http://www.pcre.org/ This is what AutoIt uses. I should have posted this before but had forgotten. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now