import RegexBuilder let regex = Regex { NegativeLookahead { Regex { Optionally(Anchor.wordBoundary.inverted) ":" ZeroOrMore(CharacterClass.anyOf(":").inverted) } } "_" NegativeLookahead { Regex { ZeroOrMore(CharacterClass.anyOf(":").inverted) ":" Optionally(Anchor.wordBoundary.inverted) } } }.wordBoundaryKind(.simple) let txt = "\u{200C}:c_huzer01:" _ = txt.matches(of: regex)