• Stars
    star
    595
  • Rank 75,217 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Swift Port of VerbalExpressions

SwiftVerbalExpressions

Build Status Carthage compatible

Swift Regular Expressions made easy

SwiftVerbalExpressions is a Swift library that helps to construct difficult regular expressions - ported from the awesome JavaScript VerbalExpressions.

Examples

Here's a couple of simple examples to give an idea of how VerbalExpressions works:

Testing if we have a valid URL

// Create an example of how to test for correctly formed URLs
let tester = VerEx()
    .startOfLine()
    .then("http")
    .maybe("s")
    .then("://")
    .maybe("www")
    .anythingBut(" ")
    .endOfLine()

// Create an example URL
let testMe = "https://www.google.com"

// Use test() method
if tester.test(testMe) {
    print("We have a correct URL") // This output will fire
}
else {
    print("The URL is incorrect")
}

// Use =~ operator
if testMe =~ tester {
    print("We have a correct URL") // This output will fire
}
else {
    print("The URL is incorrect")
}

prin(tester) // Outputs the actual expression used: "^(?:http)(?:s)?(?::\/\/)(?:www)?(?:[^ ]*)$"

Replacing strings

let replaceMe = "Replace bird with a duck"

// Create an expression that seeks for word "bird"
let verEx = VerEx().find("bird")

// Execute the expression like a normal RegExp object
let result = verEx.replace(replaceMe, with: "duck")

print(result) // Outputs "Replace duck with a duck"

Shorthand for string replace:

let result2 = VerEx().find("red").replace("We have a red house", with: "blue")

print(result2) // Outputs "We have a blue house"

API documentation

You can find the documentation for the original JavaScript repo on their wiki.

Contributions

Clone the repo and fork! Pull requests are warmly welcome!

Thanks!

Thank you to @jehna for coming up with the awesome original idea!
Thank you to @kishikawakatsumi for ObjectiveCVerbalExpressions from which I borrowed some code!

Other implementations

You can view all implementations on VerbalExpressions.github.io

Installation and use

This version is under testing, but it supports Swift Package Manager. Therefore it can be included in the project with:

        .package(
            url: "https://github.com/VerbalExpressions/SwiftVerbalExpressions.git",
            from: "

And:

        .target(
            name: "YourProject",
            dependencies: ["VerbalExpressions"]),

More Repositories

1

JSVerbalExpressions

JavaScript Regular expressions made easy
JavaScript
12,176
star
2

JavaVerbalExpressions

Java regular expressions made easy.
Java
2,621
star
3

PHPVerbalExpressions

PHP Regular expressions made easy
PHP
2,411
star
4

PythonVerbalExpressions

Python regular expressions made easy
Python
1,631
star
5

CSharpVerbalExpressions

C#
1,174
star
6

CppVerbalExpressions

C++ regular expressions made easy
C++
381
star
7

ObjectiveCVerbalExpressions

Objective-C
286
star
8

RVerbalExpressions

๐Ÿ’ฌ Create regular expressions easily
R
280
star
9

GoVerbalExpressions

Go VerbalExpressions make regular expression easy
Go
180
star
10

KotlinVerbalExpressions

Kotlin regular expressions made easy.
Kotlin
158
star
11

ScalaVerbalExpressions

Scala
80
star
12

DartVerbalExpressions

Dart Regular expressions made easy.
Dart
71
star
13

ClojureVerbalExpressions

Clojure
70
star
14

QtVerbalExpressions

C++
63
star
15

HaskellVerbalExpressions

Haskell
63
star
16

ElixirVerbalExpressions

Elixir
46
star
17

RustVerbalExpressions

Rust Port of VerbalExpressions
Rust
44
star
18

HaxeVerbalExpressions

Verbal Expressions for Haxe
Haxe
42
star
19

FSharpVerbalExpressions

Compoable F# regular expressions made easy
F#
38
star
20

implementation

In this repo we will document how each method in the library should behave
34
star
21

elm-verbal-expressions

Elm Regular expressions made easy
Elm
33
star
22

purescript-verbal-expressions

Purescript Regular expressions made easy
PureScript
24
star
23

PowerShellVerbalExpressions

PowerShell
24
star
24

PerlVerbalExpressions

Perl Regular expressions made easy
Perl
17
star
25

LuaVerbalExpressions

Lua Regular expressions made easy
Lua
13
star
26

GroovyVerbalExpressions

Groovy regular expressions made easy
Groovy
13
star
27

verbalExpressions.github.io

HTML
9
star
28

ValaVerbalExpressions

Vala regular expressions made easy
Vala
8
star
29

AS3VerbalExpressions

ActionScript
8
star
30

ErlangVerbalExpressions

Erlang
7
star
31

FreeBasicVerbalExpressions

FreeBASIC port
FreeBasic
7
star
32

DVerbalExpressions

D
6
star
33

RacketVerbalExpressions

Racket
4
star
34

DenoVerbalExpressions

TypeScript
2
star
35

GenieVerbalExpressions

Genie regular expressions made easy
JavaScript
2
star