regex - matchesInString function returning an empty Array in Swift -
regex - matchesInString function returning an empty Array in Swift -
i have code working in objective-c
nsregularexpression* regex = [[nsregularexpression alloc] initwithpattern:@"(.*?)(<[^>]+>|\\z)" options:nsregularexpressioncaseinsensitive|nsregularexpressiondotmatcheslineseparators error:nil]; nsarray* results = [regex matchesinstring:text options:nsmatchingreportprogress range:nsmakerange(0, text.length)]; but swift version not working. matchesinstring returning empty array (using same tagged text in both cases)
let regexoptions = nsregularexpressionoptions.caseinsensitive | nsregularexpressionoptions.dotmatcheslineseparators allow regex = nsregularexpression.regularexpressionwithpattern("(.*?)(<[^>]+>|\\z)", options: regexoptions, error: nil) var results = regex.matchesinstring(markuptext, options: nil, range: nsmakerange(0, countelements(markuptext))) array<nstextcheckingresult> even though documentation states matchesinstring returns array of nstextcheckingresult, noted in objective-c code (that works) array contains nssimpleregularexpressioncheckingresult objects , not nstextcheckingresult objects. empty array reported in swift version reports 0 nstextcheckingresult objects though
any thought of missing here?
update, works me:
let regexoptions:nsregularexpressionoptions? = nsregularexpressionoptions.caseinsensitive var matchingerror : nserror? allow regex = nsregularexpression(pattern: "(.*?)(<[^>]+>|\\z)", options: regexoptions!, error: &matchingerror) allow markuptext = "<html></html>" allow results = regex.matchesinstring(markuptext, options: nil, range: nsmakerange(0, countelements(markuptext))) array<nstextcheckingresult> i not sure why regexoptions has optional. may bug in compiler.
older thoughts
this may bug in xcode6b2. simplified illustration 1 line:
let regexoptions = nsregularexpressionoptions.caseinsensitive and error:
fatal error: can't disclose optional.none i file bug this.
regex swift
Comments
Post a Comment