To find credit card numbers in a string using regex in Swift, you can use the built-in NSRegularExpression
class. Here's an example implementation:
main.swift642 chars20 lines
The regex pattern used in this example will match any sequence of 13-16 digits separated by spaces or dashes. The resulting credit card numbers are returned in an array of strings. You can modify the regex pattern to match different credit card number formats if needed.
gistlibby LogSnag