A fun and functional way to write regular expressions (RegExp)

Overview

funexp

A fun and functional way to write regular expressions (RegExp).

FunExp is a useful tool for larger projects that depends on RegExp to do heavy work. It can speed up the learning process of a new person that is envolved with the project, or just make RegExp easily readable. It has a fast learning curve (faster than RegExp itself) and can be integrated with any language that supports regular expressions.

Documentation

This section will be moved to a dedicated page in the future.

  • mod

    • Represents a modifier. It depends on the RegExp target language.
      • Parameters:
        • g
          • Don't return after first match.
        • m
          • start and end match start/end of line.
        • i
          • Case insensitive match.
        • ... and many more depending on the target language.
  • start or end

    • Represents the start or ending of the capture. If the modifier m is present, will represent the start or ending of line.
  • literal or string

    • Represents a literal text. Any RegExp character will be automatically escaped.

    • Parameters:

      • optional - If it's an optional capture.
        • Default: false
    • Example:

      literal|funexp is fun?! yes!

      will be converted into

      /funexp is fun\?! yes!/`
  • space

    • Represents a literal space character ( ). It's used for legibility purposes.

    • Example:

      space

      will be converted into

      / /
  • group

    • Represents a group (capturing or non-capturing).

    • Parameters:

      • optional - If the entire group is an optional capture.
        • Default: false
      • name - The group name
      • capture - If it is a non-capturing group, used just for matching.
        • Default: true
    • Example:

      literal|This next text is
      space
      
      group(capture=false, optional=true)
          literal|surely
          space
      
      literal|optional

      will be converted into

      /This next text is (?:surely )?optional/
  • alternative

    • Represents an alternative choice.

    • Example:

      literal|I believe in
      space
      alternative
          literal|pugs
          literal|fun

      will be converted into

      /I believe in pugs|fun/
  • meta

    • Represents the meta operator (dot).
  • quantifier

    • Represents a quantifier, used to repeat a match. One of the given parameters needs to be present.

    • Parameters:

      • * - Matches zero or more times.
      • + - Matches one or more times.

API

You can use funexp directly from your code:

const funexp = require("funexp");

const regex = funexp.parse(`
literal|I love to use
space
group(name="choice")
    alternative
        literal|funexp
        literal|regexp
`);

"I love to use funexp".match(regex);

Examples

You can view examples inside the test folder.

Credits

  • pug.js
    • funexp uses pug-lexer and pug-parser as the bases for lexing and parsing the pseudo-code.

License

AGPL-3.0

You might also like...

Fun way to share some of your (already) public StackOverflow user data to the internet.

Fun way to share some of your (already) public StackOverflow user data to the internet.

ProfileOverflow A simple app leveraging StackExchange APIs to show some StackOverflow accounts information. Made for fun during a weekend as practice.

Sep 14, 2022

Cuteanime is a website where you can watch anime with Japanese subtitles, it is a fun way to study japanese.

Cuteanime is a website where you can watch anime with Japanese subtitles, it is a fun way to study japanese.

Cuteanime.moe Cuteanime is a website where you can watch anime with Japanese subtitles and lookup words with a dictionary extension like Yomichan. We

Oct 27, 2022

MySQL meets Jupyter notebooks. Grasp provides a new way to learn and write SQL, by providing a coding-notebook style with runnable blocks, markdown documentation, and shareable notebooks. ✨

MySQL meets Jupyter notebooks. Grasp provides a new way to learn and write SQL, by providing a coding-notebook style with runnable blocks, markdown documentation, and shareable notebooks. ✨

A New Way to Write & Learn SQL Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Prerequisites Installation

Sep 1, 2022

A zero-dependency, buildless, terse, and type-safe way to write HTML in JavaScript.

hdot A sensible way to write HTML in JavaScript. Type-safe. Helps you follow the HTML spec. Terse. Almost character for character with plain HTML. Bui

Oct 24, 2022

The Easiest Way To Write Twitter Threads 🐦

The Easiest Way To Write Twitter Threads 🐦

Twotion | The Easiest Way To Write Twitter Threads Write Twitter threads and post them in one click without leaving Notion. Completely Free No Need To

Nov 24, 2022

write the (w)right way!

Wrighter - A Powerful Markdown Blogger & A Writing Companion ⚡ Wrighter is originally made for the hashnode x PlanetScale hackathon It has a powerful

Dec 6, 2022

Catalogist is the easy way to catalog and make your software and (micro)services visible to your organization in a lightweight and developer-friendly way.

Catalogist is the easy way to catalog and make your software and (micro)services visible to your organization in a lightweight and developer-friendly way.

catalogist 📚 📓 📒 📖 🔖 The easy way to catalog and make your software and (micro)services visible to your organization through an API You were a pe

Dec 13, 2022

🎨 Beautify your github profile with this amazing tool, creating the readme your way in a simple and fast way 🚀 The best profile readme generator you will find ⚡

🎨 Beautify your github profile with this amazing tool, creating the readme your way in a simple and fast way 🚀 The best profile readme generator you will find ⚡

Demo Profile Readme Generator The best profile readme generator you will find! About | Technologies | Requirements | Starting | Contributing 🎯 About

Jan 1, 2023

A repository demonstrating functional techniques with C# 10 and the similarities between JavaScript, TypeScript, and C#.

A repository demonstrating functional techniques with C# 10 and the similarities between JavaScript, TypeScript, and C#.

Building up from JavaScript to TypeScript to C# 10 and .NET 6 This repository is meant to highlight some of the various functional techniques availabl

Dec 30, 2022
Owner
Matheus Giovani
23y/o dev ops and fullstack coder from Londrina / Brazil, game developer as a hobby
Matheus Giovani
A compiled-away, type-safe, readable RegExp alternative

?? magic-regexp A compiled-away, type-safe, readable RegExp alternative ✨ Changelog ?? Documentation ▶️ Online playground Features Runtime is zero-dep

Daniel Roe 1.5k Jan 8, 2023
Fun λ functional programming in JS

fp-js JavaScript Functional Programming Motivation This purposed for learning functional programming (just that). Features Auto-Curry Option Tooling s

RiN 6 Feb 4, 2022
microregex is an open source and highly curated catalog of regular expression patterns. It offers programmers RegEx snippets that can be quickly exported into a variety of programming languages and distributed around teams.

microregex - A catalog of RegEx patterns View Demo · Report Bug · Request Feature Loved the tool? Please consider contributing ✍️ to help it improve!

Sunit Shirke 4 Oct 25, 2022
A regular table library, for async and virtual data models.

A Javascript library for the browser, regular-table exports a custom element named <regular-table>, which renders a regular HTML <table> to a sticky p

J.P. Morgan Chase & Co. 285 Dec 16, 2022
Regular expression for Character classes

Regular expression for Character classes

言葉 7 Aug 21, 2022
This package is for developers to be able to easily integrate bad word checking into their projects.\r This package can return bad words in array or regular expression (regex) form.

Vietnamese Bad Words This package is for developers to be able to easily integrate bad word checking into their projects. This package can return bad

Nguyễn Quang Sáng 8 Nov 3, 2022
Learn GraphQL by building a blogging engine. Create resolvers, write schemas, write queries, design the database, test and also deploy.

GraphQL Blog graphqlblog.com Learn GraphQL by building a blogging engine. Create resolvers, write schemas, write queries, design the database, test an

GraphQLApps 6 Aug 17, 2022
Reference for How to Write an Open Source JavaScript Library - https://egghead.io/series/how-to-write-an-open-source-javascript-library

Reference for How to Write an Open Source JavaScript Library The purpose of this document is to serve as a reference for: How to Write an Open Source

Sarbbottam Bandyopadhyay 175 Dec 24, 2022
🌸 A fast and fun way to learn Japanese alphabets: hiragana & katakana. Don't wait - learn now!

Sakurator | Start learning 日本語 here Sakurator (Website publish date: ~4-6 April '22) - a personal trainer for learning Japanese alphabets (hiragana &

Anatoly Frolov 3 Jun 22, 2022
A fun way for people to share their favorite trips and destinations!

TRIP A fun way for people to share their favorite trips and destinations, and provide reviews for fellow travelers! Check out Trip at https://trip-des

Tyler 4 Jun 3, 2022