I run into Thread 1: EXC_BREAKPOINT Error
, This code should be right.
import Foundation
import RegexBuilder
let string = "https://swift.org, #swift, @swift"
let regex = Regex {
ChoiceOf {
OneOrMore(.url())
WordWithPrefix(prefix: "@")
WordWithPrefix(prefix: "#")
}
}
struct WordWithPrefix: RegexComponent {
let prefix: String
@RegexComponentBuilder
var regex: Regex<some RegexComponent> {
prefix
OneOrMore(.word)
}
}
for match in string.matches(of: regex) { // Thread 1: EXC_BREAKPOINT (code=1, subcode=0x22a78b848)
print(String(string[match.range]))
}