![]() Notice how each of those regexes are made using regex literals – the ability to create a regular expression by starting and ending your regex with a /. In the third one we’re looking for “The”, but I’ve modified the regex to be case insensitive so that it matches “the”, “THE”, and so on. Kita membuatnya bisa secara langsung atau untuk digunakan di dalam fungsi-fungsi Regex.In the second one we’re matching the range “a” through “m” only, so it will print “the dog sat on the dog”.In that first regular expression we’re asking for the range of all substrings that match any lowercase alphabetic letter followed by “at”, so that would find the locations of “cat”, “sat”, and “mat”.In case you’re not familiar with regular expressions: the var mutable is defined as shorthand to convert an input string into an NSMutableString under the covers. Print(message.replacing(/at/, with: "dog")) Some regular expression operators for Swift. Print(message.replacing("cat", with: "dog"))īut the real power of these is that they all accept regular expressions too: print(message.ranges(of: /at/)) To see what’s changing, let’s start simple and work our way up.įirst, we can now draw on a whole bunch of new string methods, like so: let message = "the cat sat on the mat" Put together this is pretty revolutionary for strings in Swift, which have often been quite a sore point when compared to other languages and platforms. SE-0357 adds many new string processing algorithms based on regular expressions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |