Coder Social home page Coder Social logo

skial / regex Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 46 KB

Helper methods to cross-compile Unicode regular expressions in Haxe.

License: Mozilla Public License 2.0

JavaScript 39.11% Haxe 60.89%
haxe unicode regular-expression regular-expressions regex utf8 utf-8 utf16 utf-16 utf32

regex's Introduction

regex

Helper methods to cross-compile Unicode regular expressions.

Note

Currently, all the code in this repo has been pulled out of the rxpattern rewrite.

The file/library regenerate.js is created by @mathiasbynens. Core functionality was ported to Haxe, see utf16/RangeUtil.hx.

Install

lix install gh:skial/regex

Dependencies

  • seri - Unicode blocks, scripts, classes & range information.
  • unifill - Haxe library for Unicode UTF{8/16/32} support

Tested Platforms

  • Tested ✅
  • Untested ➖
Php Python Java JVM C# Js/Node Interp Neko HashLink Lua CPP Flash

Usage

package ;

import be.Regex;

class Main {

    public static function main() {
        /**
            Prints either a regular expression category `\p{Ll}` or
            the range of codepoints.
        **/
        var Ll = Regex.category('Ll');
        /**
            Why `²-¹⁰-⁹`?
            `²-¹` are `\u00B2-\u00B9` and `⁰-⁹` are `\u2080-\u2089`, so if you 
            used `⁰-⁹` you would only include `⁰`, `⁴`, `⁵`, `⁶`, `⁷`, `⁸`, `⁹`.
            ---
            See https://codepoints.net/search?gc=No for more info.
        **/
        var term = '(' + Ll + Regex.pattern('[²-¹⁰-⁹]?') + ')';
        /**
            The `u` Unicode flag is required. If you skip it, you can
            get an exception on some targets.
        **/
        var repeat = Regex.pattern('(?:[ +]*)');

        var regexp = new EReg(term + repeat, 'u');
 
        /**
            For regexp engines that support categories:
            - (\p{Ll}[²-¹⁰-⁹]), (?:[ +]*)
            
            For those that don't:
            - _skipping afew so not to show 1900+ codepoints_:
            - [a-z\\xB5\\xDF-\\xF6\\xF8-\\xFF\\u0101\\u0103\\u0105...|\\uD83A[\\uDD22-\\uDD43]
            
        **/
        trace( term, repeat );

        trace( regexp.match("a⁴ + b³+c²") ); // true

        // a⁴ +
        trace( regexp.matched(0) );
    }

}

regex's People

Contributors

skial avatar

Stargazers

 avatar

Watchers

 avatar  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.