0

Is there any way using swift 3 we can match a string with Multiple regular expression patterns. In Java, we usually pass them as below

[a-zA-Z]{3}|^[^\\d].*|([\\w&&[^b]])*

Is there any similar way we can do it using Swift.

Hamish
  • 78,605
  • 19
  • 187
  • 280
user1642224
  • 61
  • 14
  • There's not Regex in Swift itself (yet). You should use Foundation's [NSRegularExpression](https://developer.apple.com/reference/foundation/nsregularexpression). – Eric Aya Feb 28 '17 at 15:45
  • Are you asking if `|` is supported by NSRegularExpression? Yes, it is. – Wiktor Stribiżew Feb 28 '17 at 16:03
  • @WiktorStribiżew I didn't try that..I don't know where I am going wrong. Do we have any func() which actually matches multiple NSRegularExpression – user1642224 Feb 28 '17 at 16:08
  • The `[\\w&&[^b]]` is most probably the culprit. In ICU, it is set as `[\\w--b]` (or `[\\w--[b]]`). As for multiple matches, no, you need to implement it. There are such questions on SO. See [Swift extract regex matches](http://stackoverflow.com/questions/27880650/swift-extract-regex-matches). – Wiktor Stribiżew Feb 28 '17 at 16:09

0 Answers0