import Foundation
let pattern = #"[^0-9a-z]?(bikini|b[i|e]rah[i|e]|b[o|u]g[i|e]l|[men|di]?cabul[i]?|cialis|[dic|menc|menyu]?umbu[i]?|dildo|[ng]?ent[o|i]t|ereksi|eroti[k|c]|gay|jemb[u|e]t|judi|[c|k]ondom|kontol|kunam|lesb[o|ian]|libido|lucah|memek|[dip|pem]?erkosa|miras|penis|pepek|porno|puting|rog[o|e]l|seks|se[k|n]sual|sex]|telanjang|telugu|tetek|titit|toge[l]?|tocil|vagina|viagra|orgasm[e]?|kemaluan|k[e]?lamin|[ngen|jan]cuk)[^0-9a-z]"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive, .dotMatchesLineSeparators])
let testString = #"persaingan dua pembalap mercedes kembali terjadi pada balapan gp formula 1 monaco. nico rosberg akhirnya sukses memutus rangkaian kemenangan rekan satu timnya, lewis hamilton yang finis di posisi kedua pada balapan yang digelar seksual seks sensual "#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = ####"###BAD###"####
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression