Giter VIP home page Giter VIP logo

regexkitx's Introduction

RegexKitX

Use the pattern-matching Force.

Inspiration

I've loved regular expressions since the beginning of my programming career back when I worked at Apple. I learned (and continue to learn) A LOT from Jeffrey Friedl's book, Mastering Regular Expression, 3rd. ed. I know they are controversial in some circles but when crafted well, there's really nothing like them.

Here's some follow-up reading about regexes:

Objective-C

This is a Regular Expression API inspired by the RegexKitLite 4.0 API that John Engelhart (@johnezang) shipped back in 2010. ("RKL4")

Basically, I'm modernizing the API as a cover for NSRegularExpression and NSTextCheckingResult.

I am doing this for several reasons:

  • How unwieldy NSRegularExpression naturally is
  • The false positives that the Clang Static Analyzer flagged in RKL4
  • The fact that RKL4 is NOT ARC-compliant
  • The fact that the low-level RKL4 C code accessing the ICU regex engine spits out OSSpinLock-based deprecation warnings on macOS 10.12 Sierra and above
  • How easy it is to forget to ALWAYS link to the ICU library on every project using RKL4 (Obviously CocoaPods solves this)
  • I wanted to provide cover API for named captures and backreferences, which NSRegularExpression supports, and RKL4 does not.

My concern is that no amount of work-arounds or modifications to all the low-level RKL4 magic code will save it from being unbuildable or free of static analyzer warnings in a future appleOS. So rather than wait for that to happen or repeatedly deal directly with the awkwardness of NSRegularExpression, I'm choosing to do RegexKitX ("RKX").

I've also added documentation that is option-clickable for all the RKX category methods.

NOTE: There's an almost-pure RKL4 API re-implementation here. This version is intended to be a drop-in replacement (with possible block-based modifications) for the original RKL4 codebase.

A few caveats:

  1. I've re-ordered and modernized some of the argument and block parameters for a number of APIs.
  2. I've renamed a few APIs as well to make them grammatically and contextually consistent and follow Apple naming conventions from NSString.
  3. The regex syntax is 100%-pure ICU syntax (the original RKL4 diverged slightly away from ICU).
  4. For some of the block methods, I'm exposing NSEnumerationOptions to provide an option for directional control of the enumeration. As usual, NSEnumerationConcurrent behavior is undefined.

Swift

I have deprecated the SwiftRegexKitX extension and tests. The new Apple Swift Regex additions pretty much negate any prior extensions. Apple has added a Regex struct and associated types along with a RegexBuilder DSL, which is much more sophisticated than anything I came up with for SwiftRegexKitX.

regexkitx's People

Contributors

samkrishna avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

regexkitx's Issues

Implement rangesOfRegex:... method

Write a method to match ALL of the ranges of instances of a regex within a string.

This way it will be easier to enumerate through either the regexes or the substrings separated by the regex.

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.