https://github.com/meniny/colaexpression
💻A regular expression framework written in Swift.
https://github.com/meniny/colaexpression
regex regular-expression swift
Last synced: about 1 year ago
JSON representation
💻A regular expression framework written in Swift.
- Host: GitHub
- URL: https://github.com/meniny/colaexpression
- Owner: Meniny
- License: mit
- Created: 2017-07-14T13:05:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-06T08:37:08.000Z (about 7 years ago)
- Last Synced: 2025-04-07T22:46:41.853Z (about 1 year ago)
- Topics: regex, regular-expression, swift
- Language: Swift
- Homepage:
- Size: 818 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
***
## What's this?
`ColaExpression` is a Cross-Platform Regular Expression Library written in Swift.
## Requirements
* iOS 9.0+
* macOS 10.10+
* watchOS 3.0+
* tvOS 9.0+
* Xcode 9 with Swift 4
## Installation
#### CocoaPods
```ruby
pod 'ColaExpression'
```
## Contribution
You are welcome to fork and submit pull requests.
## License
`ColaExpression` is open-sourced software, licensed under the `MIT` license.
## Usage
#### `isMatch() -> Bool`
```swift
let pattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
let str = "admin@meniny.cn"
```
```swift
let cola = ColaExpression(pattern)
if cola.isMatch(with: str) {
print("\(str) is a valid email")
// admin@meniny.cn is a valid email
}
```
```swift
if str.isMatch(pattern: pattern) {
print("\(str) is a valid email")
// admin@meniny.cn is a valid email
}
```
#### `matches() -> [String]`
```swift
let pattern = "[a-z]{3}"
let str = "AAAbbbCCCdddEEEfff"
```
```swift
let cola = ColaExpression(pattern)
let matches = cola.matches(of: str)
// ["bbb", "ddd", "fff"]
```
```swift
let matches = str.matches(pattern: pattern)
// ["bbb", "ddd", "fff"]
```
#### `replaceOccurences() -> String`
```swift
let pattern = "[a-z]"
let str = "AAAbbbCCCdddEEEfff"
let replacement = "-"
```
```swift
let cola = ColaExpression(pattern)
let replaced = cola.replaceOccurences(in: str, with: replacement)
// AAA---CCC---EEE---
```
```swift
let replaced = str.replaceOccurences(matches: pattern, with: replacement)
// AAA---CCC---EEE---
```