When I use matcher.group(1), the value it's not corresponding to the regex. I got the value but some extra characters are present. I think it's about to find the substring from the range.
I replaced the function:
public func group(_ i: Int) -> String? {
let b = matches[index]
#if !os(Linux) && !swift(>=4)
let c = b.rangeAt(i)
#else
let c = b.range(at: i)
#endif
if(c.location == NSNotFound) {return nil}
let result = string.substring(c.location, c.length)
return result
}
by:
public func group(_ i: Int) -> String {
let b = matches[index]
let result = NSString(string: string).substring(with: b.range)
return result
}
and I got the right value.
Maybe Matcher can be initialized with the NSString to avoid redundant instance
When I use
matcher.group(1)
, the value it's not corresponding to the regex. I got the value but some extra characters are present. I think it's about to find the substring from the range.I replaced the function:
by:
and I got the right value.
Maybe Matcher can be initialized with the NSString to avoid redundant instance