regex - how to use regular expressions in swift? -
i trying write json parser in swift. writing functions parsing different parts of json code. wrote string parser detects string json data, checking start \" , if meet \" separated , returned string when met json text:
{"gd$etag": "w\/\"d0qcqx4zfcp7i2a9xrzqfkw.\""}
the function wrote failed in above case since in value part has recognise whole string while mine working collect only
w\/
since gave condition starting , ending \" when searched online understood in relation regular expressions. me out solve this!
is looking for?
import foundation let str: nsstring = "w\\/\\\"d0qcqx4zfcp7i2a9xrzqfkw.\\\"" let regex = "\\\\\".*\\\\\"" // finds range starts \" , ends \" let range = str.rangeofstring(regex, options: .regularexpressionsearch) let match: nsstring = str.substringwithrange(range) //removes \" start , end. let innerstring = match.substringwithrange(nsmakerange(2, match.length-4))
Comments
Post a Comment