regelk
v1.0.3
Published
RegElk JavaScript version
Readme
RegElk-JS
A linear regular expression engine demo for JavaScript, translated from the OCaml RegElk project and packaged as an npm module for use in Node.js and modern browsers.
Installation
npm install regelkImport Methods
CommonJS (Node.js)
const regElk = require("regelk");ES Module (Browser or ES6 environments)
import regElk from "regelk";Usage Examples
Basic Matching
const regElk = require("regelk");
const regex = /a\n(.+)/;
const str = "a\nb";
const result = regElk(regex, str);
console.log(result);
// Outputs match result object containing capture group informationUsing String as Regex Source
const result = regElk("a(.+)c", "abcd");
console.log(result);Using RegExp Objects
const regex = /hello (world)/
const result = regElk(regex, "Hello World!");
console.log(result);Return Value
The function returns a match result object with the following structure:
// Array of captures, where each element represents a capture value
// Group 0 is the full match
[
"hello world",
"world"
]If no match is found, null will be returned.
