-1

I am trying to parse string data in Swift, the best solution that I can think of is using a regular expression. The problem is with detecting a substring with the pattern {{...}} The ... represents a string of any length. I created a regular expression using an online debugger. Here is the expression and the corresponding result:

the expression and the corresponding result

But when I use same regular expression in Swift, it doesn't work. Below is the code that I am using.

if let match = data.range(of: "{{(.*)}}", options: .regularExpression) 
{ some code logic }

But it is not working. I have hardcoded in the exact same string as in the test string above.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
Zia ur Rehman
  • 331
  • 1
  • 2
  • 20

1 Answers1

-1

You should escape the curly braces with backslashes:

let match = data.range(of: "\\{\\{(.*)\\}\\}", options: .regularExpression)
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223