Created
December 22, 2015 08:52
-
-
Save venj/8bc7f3f442a9aea343ae to your computer and use it in GitHub Desktop.
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
//: Playground - noun: a place where people can play | |
import Foundation | |
import Darwin | |
let regex = UnsafeMutablePointer<regex_t>.alloc(1) | |
let regexString = "^[[:alnum:]]+$" | |
let regex_str = regexString.cStringUsingEncoding(NSUTF8StringEncoding)! | |
if (regcomp(regex, regex_str, REG_ICASE | REG_EXTENDED) != 0) { | |
print("Error compile regex") | |
exit(255) | |
} | |
let str = "11asdfas22".cStringUsingEncoding(NSUTF8StringEncoding)! | |
let errorcode = regexec(regex, str, 0, nil, 0) | |
if (errorcode == 0) { | |
print("matches found.") | |
} | |
else if (errorcode == REG_NOMATCH) { | |
print("No matches.") | |
} | |
else { // REG_ESPACE | |
print("Out of memory!") | |
exit(255) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment