Last active
May 2, 2024 02:16
-
-
Save odzhan/3bb22d1ed8b5b0592b3fc2b71b8504e4 to your computer and use it in GitHub Desktop.
Simple regexp example using IRegExp interface.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Simple regexp example using IRegExp interface. | |
// | |
/** | |
# Found 4 matches. | |
> test@gmail.com | |
> spam@yahoo.com | |
> mailme@microsoft.com | |
> nospam@hotmail.co.uk | |
*/ | |
#import "RegExp.tlb" no_namespace | |
int | |
main(int argc, char *argv[]) { | |
LPCTSTR exp = "([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)"; | |
LPCTSTR str = "test@gmail.com spam@yahoo.com mailme@microsoft.com nospam@hotmail.co.uk"; | |
CoInitialize(NULL); | |
static IRegExpPtr regExp(__uuidof(RegExp)); | |
regExp->PutGlobal(VARIANT_TRUE); | |
regExp->PutPattern(exp); | |
if (regExp->Test(str) == VARIANT_TRUE) { | |
IMatchCollectionPtr matches = regExp->Execute(str); | |
if (matches->GetCount() > 0) { | |
printf("\n # Found %d matches.\n\n", matches->GetCount()); | |
for (int i=0; i<matches->Count; i++) { | |
IMatchPtr match = matches->GetItem(i); | |
printf(" > %s\n", (char*)match->GetValue()); | |
} | |
} else printf("No matches.\n"); | |
} else printf("Test() failed.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment