All Projects → micromatch → expand-brackets

micromatch / expand-brackets

Licence: MIT license
Expand POSIX bracket expressions (character classes) in glob patterns.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to expand-brackets

globrex
Glob to regular expression with support for extended globs.
Stars: ✭ 52 (+100%)
Mutual labels:  regex, regexp, glob, regular-expression, globbing
Micromatch
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Stars: ✭ 1,979 (+7511.54%)
Mutual labels:  regex, glob, regular-expression, micromatch, globbing
extglob
Extended globs. Add (almost) the expressive power of regular expressions to glob patterns.
Stars: ✭ 25 (-3.85%)
Mutual labels:  regex, glob, regular-expression, globbing
Picomatch
Blazing fast and accurate glob matcher written JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.
Stars: ✭ 393 (+1411.54%)
Mutual labels:  regex, regexp, glob, regular-expression
Emoji Regex
A regular expression to match all Emoji-only symbols as per the Unicode Standard.
Stars: ✭ 1,134 (+4261.54%)
Mutual labels:  regex, regexp, regular-expression
Is Glob
If you use globs, this will make your code faster. Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience. 55+ million downloads.
Stars: ✭ 63 (+142.31%)
Mutual labels:  regex, regexp, glob
Globbing
Introduction to "globbing" or glob matching, a programming concept that allows "filepath expansion" and matching using wildcards.
Stars: ✭ 86 (+230.77%)
Mutual labels:  regex, glob, regular-expression
cregex
A small implementation of regular expression matching engine in C
Stars: ✭ 72 (+176.92%)
Mutual labels:  regex, regexp, regular-expression
Regulex
🚧 Regular Expression Excited!
Stars: ✭ 4,877 (+18657.69%)
Mutual labels:  regex, regexp, regular-expression
Orchestra
One language to be RegExp's Successor. Visually readable and rich, technically safe and extended, naturally scalable, advanced, and optimized
Stars: ✭ 103 (+296.15%)
Mutual labels:  regex, regexp, regular-expression
regexp-expand
Show the ELisp regular expression at point in rx form.
Stars: ✭ 18 (-30.77%)
Mutual labels:  regex, regexp, regular-expression
Regexr
For composing regular expressions without the need for double-escaping inside strings.
Stars: ✭ 53 (+103.85%)
Mutual labels:  regex, regexp, regular-expression
Commonregex
🍫 A collection of common regular expressions for Go
Stars: ✭ 733 (+2719.23%)
Mutual labels:  regex, regexp, regular-expression
Hyperscan Java
Match tens of thousands of regular expressions within milliseconds - Java bindings for Intel's hyperscan 5
Stars: ✭ 66 (+153.85%)
Mutual labels:  regex, regexp, regular-expression
Onigmo
Onigmo is a regular expressions library forked from Oniguruma.
Stars: ✭ 536 (+1961.54%)
Mutual labels:  regex, regexp, regular-expression
Regexpu
A source code transpiler that enables the use of ES2015 Unicode regular expressions in ES5.
Stars: ✭ 201 (+673.08%)
Mutual labels:  regex, regexp, regular-expression
Grex
A command-line tool and library for generating regular expressions from user-provided test cases
Stars: ✭ 4,847 (+18542.31%)
Mutual labels:  regex, regexp, regular-expression
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (-23.08%)
Mutual labels:  regex, regexp, glob
Regexp2
A full-featured regex engine in pure Go based on the .NET engine
Stars: ✭ 389 (+1396.15%)
Mutual labels:  regex, regexp, regular-expression
moar
Deterministic Regular Expressions with Backreferences
Stars: ✭ 19 (-26.92%)
Mutual labels:  regex, regexp, regular-expression

expand-brackets NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Expand POSIX bracket expressions (character classes) in glob patterns.

Install

Install with npm:

$ npm install --save expand-brackets

Install with yarn:

$ yarn add expand-brackets

Usage

var brackets = require('expand-brackets');
brackets(string[, options]);

Params

The main export is a function that takes the following parameters:

  • pattern {String}: the pattern to convert
  • options {Object}: optionally supply an options object
  • returns {String}: returns a string that can be used to create a regex

Example

console.log(brackets('[![:lower:]]'));
//=> '[^a-z]'

API

brackets

Parses the given POSIX character class pattern and returns a string that can be used for creating regular expressions for matching.

Params

  • pattern {String}
  • options {Object}
  • returns {Object}

.match

Takes an array of strings and a POSIX character class pattern, and returns a new array with only the strings that matched the pattern.

Params

  • arr {Array}: Array of strings to match
  • pattern {String}: POSIX character class pattern(s)
  • options {Object}
  • returns {Array}

Example

const brackets = require('expand-brackets');
console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]'));
//=> ['a']

console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+'));
//=> ['a', 'ab']

.isMatch

Returns true if the specified string matches the given brackets pattern.

Params

  • string {String}: String to match
  • pattern {String}: Poxis pattern
  • options {String}
  • returns {Boolean}

Example

const brackets = require('expand-brackets');

console.log(brackets.isMatch('a.a', '[[:alpha:]].[[:alpha:]]'));
//=> true
console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]'));
//=> false

.matcher

Takes a POSIX character class pattern and returns a matcher function. The returned function takes the string to match as its only argument.

Params

  • pattern {String}: Poxis pattern
  • options {String}
  • returns {Boolean}

Example

const brackets = require('expand-brackets');
const isMatch = brackets.matcher('[[:lower:]].[[:upper:]]');

console.log(isMatch('a.a'));
//=> false
console.log(isMatch('a.A'));
//=> true

.makeRe

Create a regular expression from the given pattern.

Params

  • pattern {String}: The pattern to convert to regex.
  • options {Object}
  • returns {RegExp}

Example

const brackets = require('expand-brackets');
const re = brackets.makeRe('[[:alpha:]]');
console.log(re);
//=> /^(?:[a-zA-Z])$/

.create

Parses the given POSIX character class pattern and returns an object with the compiled output and optional source map.

Params

  • pattern {String}
  • options {Object}
  • returns {Object}

Example

const brackets = require('expand-brackets');
console.log(brackets('[[:alpha:]]'));
// { options: { source: 'string' },
//   input: '[[:alpha:]]',
//   state: {},
//   compilers:
//    { eos: [Function],
//      noop: [Function],
//      bos: [Function],
//      not: [Function],
//      escape: [Function],
//      text: [Function],
//      posix: [Function],
//      bracket: [Function],
//      'bracket.open': [Function],
//      'bracket.inner': [Function],
//      'bracket.literal': [Function],
//      'bracket.close': [Function] },
//   output: '[a-zA-Z]',
//   ast:
//    { type: 'root',
//      errors: [],
//      nodes: [ [Object], [Object], [Object] ] },
//   parsingErrors: [] }

Options

options.sourcemap

Generate a source map for the given pattern.

Example

var res = brackets('[:alpha:]', {sourcemap: true});

console.log(res.map);
// { version: 3,
//   sources: [ 'brackets' ],
//   names: [],
//   mappings: 'AAAA,MAAS',
//   sourcesContent: [ '[:alpha:]' ] }

POSIX Character classes

The following named POSIX bracket expressions are supported:

  • [:alnum:]: Alphanumeric characters (a-zA-Z0-9])
  • [:alpha:]: Alphabetic characters (a-zA-Z])
  • [:blank:]: Space and tab ([ t])
  • [:digit:]: Digits ([0-9])
  • [:lower:]: Lowercase letters ([a-z])
  • [:punct:]: Punctuation and symbols. ([!"#$%&'()*+, -./:;<=>?@ [\]^_``{|}~])
  • [:upper:]: Uppercase letters ([A-Z])
  • [:word:]: Word characters (letters, numbers and underscores) ([A-Za-z0-9_])
  • [:xdigit:]: Hexadecimal digits ([A-Fa-f0-9])

See posix-character-classes for more details.

Not supported

Changelog

v4.0.0

Breaking changes

  • Snapdragon was updated to 0.12. Other packages that integrate expand-brackets need to also use snapdragon 0.12.
  • Minimum Node.JS version is now version 4.

v3.0.0

Breaking changes

  • Snapdragon was updated to 0.11. Other packages that integrate expand-brackets need to also use snapdragon 0.11.

v2.0.0

Breaking changes

  • The main export now returns the compiled string, instead of the object returned from the compiler

Added features

  • Adds a .create method to do what the main function did before v2.0.0

v0.2.0

In addition to performance and matching improvements, the v0.2.0 refactor adds complete POSIX character class support, with the exception of equivalence classes and POSIX.2 collating symbols which are not relevant to node.js usage.

Added features

  • parser is exposed, so that expand-brackets parsers can be used by upstream parsers (like micromatch)
  • compiler is exposed, so that expand-brackets compilers can be used by upstream compilers
  • source maps

source map example

var brackets = require('expand-brackets');
var res = brackets('[:alpha:]');
console.log(res.map);

{ version: 3,
     sources: [ 'brackets' ],
     names: [],
     mappings: 'AAAA,MAAS',
     sourcesContent: [ '[:alpha:]' ] }

About

Related projects

  • braces: Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… more | homepage
  • extglob: Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… more | homepage
  • micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | homepage
  • nanomatch: Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

Commits Contributor
69 jonschlinkert
13 danez
2 MartinKolarik
2 es128
1 doowb
1 eush77
1 mjbvz

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on April 30, 2018.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].