Giter VIP home page Giter VIP logo

perfect-regex's Introduction

String Extension of Regular Expression 简体中文

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

This project provides a light weight / simple regular expression extension for Swift String.

This package builds with Swift Package Manager and is part of the Perfect project. It was written to be stand-alone and so does not require PerfectLib or any other components.

Ensure you have installed and activated the latest Swift 4.0 tool chain.

Building

Add this project as a dependency in your Package.swift file.

.package(url:"https://github.com/PerfectSideRepos/Perfect-RegEx.git", from: "3.1.0")

... 
dependencies: ["Regex"]

Then please add the following line to the beginning part of swift sources:

import Regex

Quick Start

The following demo shows how to extract substring ranges with a pattern:

var source = "there is a bloody bad bread on my bed."

let ranges = source.match(pattern: "b[a-z]+d")

// it will figure out the range of `blood`, `bad` `bread` and `bed`
let found:[String] = ranges.map { String(source[$0]) }
print("found", found)


// you can do further operations, such as remove:
source.removeSubrange(ranges[0])

print(source)
// the result should be:
// there is a y bad bread on my bed.

API Info

extension String {
	/// test if the string contains certain pattern
 	/// - parameters:
 	///   - pattern: string to recognize
 	/// - return: true for found
  public func contains(pattern: String) -> Bool

  /// find string ranges
  /// - parameters:
  ///   - pattern: string to recognize
  /// - return: a string range array
  public func match(pattern: String) -> [Range<String.Index>]
}

Issues

We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.

A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues

Further Information

For more information on the Perfect project, please visit perfect.org.

perfect-regex's People

Contributors

rockfordwei avatar iamjono avatar kjessup avatar

Watchers

Barry Kostjens avatar James Cloos 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.