oreg is currently in development and is not ready for production use.
Please feel free to take a look but don't bank on anything working.
oreg is a JavaScript library designed to provide an Object-Relational Mapping (ORM) Query Builder-like interface for constructing regular expressions. This intuitive and fluent API simplifies the process of creating complex regular expressions, making your code more readable and maintainable.
- Intuitive: The API is designed to be intuitive and easy to use.
- Human Readable: Oreg is designed to make Regular Expressions more readable and maintainable.
- Chainable Methods: Build regular expressions using a fluent, chainable API.
- Lightweight: Oreg is a small library with no dependenciess
To use Oreg in your project, install it via npm:
npm install oreg
Or, if you prefer using yarn:
yarn add oreg
First, import Oreg into your JavaScript file:
import { oreg } from 'oreg';
Here's a simple example to match a string that starts with "Hello":
const regex = oreg().startsWith("Hello").getRegexString();
console.log(regex); // Outputs: "^Hello"
Building a more complex regular expression:
const regex = oreg()
.startsWith("http")
.chars("://")
.anyOf([o => o.chars("www."), o => o.digits()])
.endsWith(".com")
.caseInsensitive()
.getRegexString();
console.log(regex); // Outputs the corresponding regex pattern
Begins the regular expression with the specified prefix.
Ends the regular expression with the specified suffix.
Includes any of the specified patterns.
Includes the specified characters in the pattern.
Shortcut for adding a digit pattern (\d
).
Makes the entire regular expression case-insensitive.
Returns the regular expression as a string.
Returns the regex string without slashes and modifiers.
Returns the regex string without modifiers.
Contributions are welcome!
Oreg is MIT licensed.