Coder Social home page Coder Social logo

objectivecverbalexpressions's Introduction

ObjectiveCVerbalExpressions

version platform Build Status Coverage Status

Objective-C Regular Expressions made easy

ObjectiveCVerbalExpressions is a Objective-C library that helps to construct difficult regular expressions - ported from the awesome JavaScript VerbalExpressions.

Installation

pod 'VEVerbalExpressions'

From source

Drags VerbalExpressions.h and VerbalExpressions.m into your projects and import "VerbalExpressions.h"

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
VerbalExpressions *tester = VerEx()
.startOfLine(YES)
.then(@"http")
.maybe(@"s")
.then(@"://")
.maybe(@"www")
.anythingBut(@" ")
.endOfLine(YES);

// Create an example URL
NSString *testMe = @"https://www.google.com";

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

NSLog(@"%@", tester); // Ouputs the actual expression used: "^(http)(s)?(:�_/�_/)(www)?([^ ]*)$"

Replacing strings

NSString *replaceMe = @"Replace bird with a duck";

// Create an expression that seeks for word "bird"
VerbalExpressions *verEx = VerEx().find(@"bird");

// Execute the expression like a normal RegExp object
NSString *result = verEx.replace(replaceMe, @"duck" );

NSLog(@"%@", result); // Outputs "Replace duck with a duck"

Shorthand for string replace:

NSString *result2 = VerEx().find(@"red").replace(@"We have a red house", @"blue");

NSLog(@"%@", result2); // Outputs "We have a blue house"

API documentation

I haven't added much documentation to this repo yet, but you can find the documentation for the original JavaScript repo on their wiki. Most of the methods have been ported as of v0.1.0 of the JavaScript repo. Just be sure to use the syntax explained above rather than the dot notation :)

Contributions

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

Issues

  • I haven't yet ported the stopAtFirst method.

Thanks!

Thank you to @jehna for coming up with the awesome original idea!

Other implementations

You can view all implementations on VerbalExpressions.github.io

objectivecverbalexpressions's People

Contributors

kishikawakatsumi avatar mihai-vlc avatar ishkawa avatar

Watchers

James Cloos avatar Noname avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.