0

I simply have regex like this:

let email = "^(?:(?:(?:(?: )*(?:(?:(?:\\t| )*\\r\\n)?(?:\\t| )+))+(?: )*)|(?: )+)?(?:(?:(?:[-A-Za-z0-9!#$%&’*+/=?^_'{|}~]+(?:\\.[-A-Za-z0-9!#$%&’*+/=?^_'{|}~]+)*)|(?:\"(?:(?:(?:(?: )*(?:(?:[!#-Z^-~]|\\[|\\])|(?:\\\\(?:\\t|[ -~]))))+(?: )*)|(?: )+)\"))(?:@)(?:(?:(?:[A-Za-z0-9](?:[-A-Za-z0-9]{0,61}[A-Za-z0-9])?)(?:\\.[A-Za-z0-9](?:[-A-Za-z0-9]{0,61}[A-Za-z0-9])?)*)|(?:\\[(?:(?:(?:(?:(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))\\.){3}(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5]))))|(?:(?:(?: )*[!-Z^-~])*(?: )*)|(?:[Vv][0-9A-Fa-f]+\\.[-A-Za-z0-9._~!$&'()*+,;=:]+))\\])))(?:(?:(?:(?: )*(?:(?:(?:\\t| )*\\r\\n)?(?:\\t| )+))+(?: )*)|(?: )+)?$"
let url = "https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)"

Is there a way to write it using multiline string in Swift?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • And if you try it doesn't work? With a `\`at the end of each line to indicate to not break a line? See https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html#ID286 & https://www.hackingwithswift.com/sixty/1/3/multi-line-strings ? Is that what you meant? – Larme Apr 02 '21 at 08:24
  • What exactly do you mean?;) Because I dont get it...;) – Bartłomiej Semańczyk Apr 02 '21 at 09:59
  • What would you want to have (if it was possible)? It's unclear. But else, you can put a `\` at the end of the line in the multiple string, as explained in the links. – Larme Apr 02 '21 at 10:02
  • I think `` should be a backslash `\ ` – Joakim Danielson Apr 02 '21 at 10:13
  • Indeed, I didn't check the output of the comment as it was not correctly interpreted. : \ – Larme Apr 02 '21 at 10:16
  • IMO instead of using a regex to validate an email you should simply send a confirmation email to check if it is valid or not. The email might be valid but unreachable by the user. https://stackoverflow.com/questions/742451/what-is-the-simplest-regular-expression-to-validate-emails-to-not-accept-them-bl/742455#comment554166_742455 – Leo Dabus Apr 02 '21 at 13:31

0 Answers0