@@ -113,6 +113,39 @@ public extension String {
113
113
return nil
114
114
}
115
115
116
+ /**
117
+ Check is string with this pattern included in string
118
+
119
+ :param: pattern Pattern to match
120
+ :param: ignoreCase true for case insensitive matching
121
+ :returns: true if contains match, otherwise false
122
+ */
123
+ func containsMatch ( pattern: String , ignoreCase: Bool = false ) -> Bool ? {
124
+ if let regex = ExSwift . regex ( pattern, ignoreCase: ignoreCase) {
125
+ let range = NSMakeRange ( 0 , count ( self ) )
126
+ return regex. firstMatchInString ( self , options: . allZeros, range: range) != nil
127
+ }
128
+
129
+ return nil
130
+ }
131
+
132
+ /**
133
+ Replace all pattern matches with another string
134
+
135
+ :param: pattern Pattern to match
136
+ :param: replacementString string to replace matches
137
+ :param: ignoreCase true for case insensitive matching
138
+ :returns: true if contains match, otherwise false
139
+ */
140
+ func replaceMatches ( pattern: String , withString replacementString: String , ignoreCase: Bool = false ) -> String ? {
141
+ if let regex = ExSwift . regex ( pattern, ignoreCase: ignoreCase) {
142
+ let range = NSMakeRange ( 0 , count ( self ) )
143
+ return regex. stringByReplacingMatchesInString ( self , options: . allZeros, range: range, withTemplate: replacementString)
144
+ }
145
+
146
+ return nil
147
+ }
148
+
116
149
/**
117
150
Inserts a substring at the given index in self.
118
151
0 commit comments