Swiftpack.co - Package - nerzh/swift-extensions-pack

swift-extensions-pack

Swift REGEXP ( regular expression ) : extensions for String

regexp: Find String matches

"hello world"[#"[^\s]+"#]
/// => String: "hello"
/// => String: "" if no matches

regexp: Return Bool

"hello world"[#"[^\s]+"#]
/// => Bool: true

regexp: Return Dictionary of numbered matches

"match".regexp(#"(ma)([\s\S]+)"#)
/// => Dictionary: [0: "match", 1: "ma", 2:"tch"]

regexp: Replace First match to value

"111 Hello 111".replaceFirst(#"\d+"#, "!!!") 
/// => String: "!!! Hello 111"
var str = "111 Hello 111"
str.replaceFirstSelf(#"\d+"#, "!!!")
/// Mutating "!!! Hello 111"
"111 Hello 111".replaceFirst(#"\d+"#) { (value) -> String in  
    return value == "111" ? "???" : value
}
///  => "??? Hello 111"
var str = "111 Hello 111"
str.replaceFirstSelf(#"\d+"#) { (value) -> String in  
    return value == "111" ? "???" : value
}
/// Mutate to "??? Hello 111"

regexp: Replace All match to values

"111 Hello 111".replace(#"\d+"#, "!!!")
/// =>  "!!! Hello !!!"
var str = "111 Hello 111"
str.replaceSelf(#"\d+"#, "!!!")
/// Mutate to  "!!! Hello !!!"
"111 Hello 222".replace(#"\d+"#) { (value) -> String in  
    return value == "222" ? "111" : value
}
/// =>  "111 Hello 111"
var str = "111 Hello 222"
str.replaceSelf(#"\d+"#) { (value) -> String in  return value == "222" ? "111" : value }
/// Mutate to "111 Hello 111"

regexp: Get All Match Ranges

"23 34".matchesWithRange(#"\d+"#)
/// => [Range<String.Index> : "23", Range<String.Index> : "34"]
"23 34".matchesWithRange(#"\d+"#)
/// => [[Range<String.Index> : "23", Range<String.Index> : "34"]]

Github

link
Stars: 0

Used By

Total: 0

Releases

- 2020-08-27 12:52:15

- 2020-08-24 12:11:07

- 2020-08-07 10:40:16

- 2020-08-06 19:38:13

Fix ios compile - 2020-07-11 10:10:42

- 2020-06-24 18:01:28

- 2020-05-31 14:33:56

- 2020-04-06 05:20:43

- 2020-03-17 02:04:33

- 2020-03-17 02:01:13

- 2020-03-17 01:09:52

- 2020-03-17 01:00:20

- 2020-02-01 20:25:17

- 2020-01-26 01:44:38

- 2020-01-26 00:25:40

- 2020-01-20 03:27:02

- 2020-01-20 00:53:28

- 2020-01-20 00:49:23

- 2020-01-20 00:43:46

- 2019-12-19 16:50:58

- 2019-12-16 16:09:02

- 2019-12-16 16:02:20

- 2019-12-16 16:00:00

- 2019-12-16 14:02:04

- 2019-12-16 13:55:03

- 2019-12-16 13:26:14

- 2019-11-21 20:59:58

For SPM - 2019-11-18 00:38:58