pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/SimpleRegex/SRL-JavaScript

gin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/repository-6534fbc3f5e83ac0.css" /> GitHub - SimpleRegex/SRL-JavaScript: JavaScript implementation of SRL. · GitHub
Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SRL-JavaScript

JavaScript implementation of Simple Regex 🎉🎉🎉

npm version Build Status codecov

Because of the JavaScript regex engine, there is something different from Simple Regex

  • Support as to assign capture name with CODE but not regex engine.
  • NOT support if already had/if not already had
  • NO first match and NO all lazy, since in JavaScript lazy means non-greedy (matching the fewest possible characters).

Installation

npm install srl

Usage

Class SRL accepts a Simple Regex Language string as input, and return the builder for the query.

The builder can agent test/exec method to the generated regex object. Or you can use get() to take the generated regex object.

const SRL = require('srl')
const query = new SRL('letter exactly 3 times')

query.isMatching('aaa') // true
query.getMatch('aaa') // [ 'aaa', index: 0, input: 'aaa' ]

query
    .digit()
    .neverOrMore()
    .mustEnd()
    .get() // /[a-z]{3}[0-9]*$/g

Required Node 8.0+ for the ES6 support, Or you can use Babel to support Node below 6.0.

Using Webpack and babel-loader to pack it if want to use in browsers.

Additional

In SRL-JavaScript we apply g flag as default to follow the Simple Regex "standard", so we provide more API to use regex conveniently.

  • isMatching - Validate if the expression matches the given string.

     const query = new SRL('starts with letter twice')
     query.isMatching(' aa') // false
     query.isMatching('bbb') // true
  • getMatch - Get first match of the given string, like run regex.exec once.

    const query = new SRL('capture (letter twice) as word whitespace')
    
    query.getMatch('aa bb cc dd') // [ 'aa ', 'aa', index: 0, input: 'aa bb cc dd', word: 'aa' ]
  • getMatches - Get all matches of the given string, like a loop to run regex.exec.

    const query = new SRL('capture (letter twice) as word whitespace')
    
    query.getMatches('aa bb cc dd')
    /**
     * [ 
     *     [ 'aa ', 'aa', index: 0, input: 'aa bb cc dd', word: 'aa' ],
     *     [ 'bb ', 'bb', index: 3, input: 'aa bb cc dd', word: 'bb' ],
     *     [ 'cc ', 'cc', index: 6, input: 'aa bb cc dd', word: 'cc' ] 
     * ]
     */
  • removeModifier - Remove specific flag.

     const query = new SRL('capture (letter twice) as word whitespace')
     
     query.removeModifier('g')
     query.get() // /([a-z]{2})\s/

Development

First, clone repo and init submodule for test.

SRL-JavaScript depends on Mocha and Istanbul to test code. You can use them like this:

npm install

npm test # test 
npm run coverage # Get coverage locally 

How to write Rules, see: Test-Rules.

License

SRL-JavaScript is published under the MIT license. See LICENSE for more information.

About

JavaScript implementation of SRL.

Resources

Stars

139 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy