Skip to content

Instantly share code, notes, and snippets.

@fghber
Last active July 15, 2024 04:34
Show Gist options
  • Save fghber/e4a7e421993f393ffffb44b5fe7d7923 to your computer and use it in GitHub Desktop.
Save fghber/e4a7e421993f393ffffb44b5fe7d7923 to your computer and use it in GitHub Desktop.

RegEx

Online Regex Tester Suites & Code Generators

  • regex101 Online regex tester for PHP, PCRE, JavaScript and Python that highlights pattern and matches on the fly. Also features a code generator and a regex debugger!
  • myregextester Sports a separate regex split tester and allows to optimize patterns (I guess this is based on Perl's Regexp::Optimizer module).
  • regexr Online regex tester with good regex replace and explain functionality.
  • debuggex Shows neat expression diagrams (not active anymore).
  • regexper translates regular expressions into an SVG image (for documentation or embedding)
  • RexV2 Evaluator for PHP PCRE, PHP Posix!, Perl, Python, Javascript, Node.JS!

Regex Expression Generator, Code Generator & Explanator

  • txt2re: regular expression generator (with code generator for Perl, PHP php python java javascript coldfusion c c++ ruby vb vbscript j# c# c++.net vb.net)
  • Perl YAPE::Regex::Explain
  • Regex Generator++ Automatic Generation of Text Extraction Patterns from Examples
  • frak frak transforms collections of strings into regular expressions. Available as a command line utility (Clojure) and a JavaScript library.
  • RegexGuide not a real geneartor, more a learning tool that shows how a simple regex pattern could look like based on user input and some user requirements. Could be helpful for starters.

Regex Pattern Libraries

  • http://regexlib.com/ Regular Expression Library. Currently has about 8000 expressions from roughly 2500 contributors (most are subpar IMHO).

Langauge-specifc Regex Tester

Here are language/flavor specific online regex testers listed. The order of the listings is intentional. The most useful tools (in my view) for the specific flavor are listed first, then alternative and secondary testers follow.

.NET Regex Tester

Java Regex

JavaScript/ECMAScript

Node.js

http://www.rexv.org/

Perl

http://www.regexplanet.com/advanced/perl/index.html
http://www.rexv.org/

PHP

PHP Live Regex A Live Regular Expression Tester for PHP

R

https://spannbaueradam.shinyapps.io/r_regex_tester/
http://rextester.com/l/r_online_compiler

Ruby

http://rubular.com/
http://refiddle.com/

Google Analytics Regex Tester

http://www.analyticsmarket.com/freetools/regex-tester (and a general GA RE usage guide)

Utilities

Reverse Regex Random String Generators / Xeger

The principle is: Regex -> NFA, NFA -> minimal DFA, DFS-walk through the DFA (collecting all characters)

Python

  • sre_yield: a Python library, generate all values that can match a given regular expression, or count possible matches efficiently
  • rstr Random Strings in Python is a helper module to generating random strings of various types fuzzy testing, generating dummy data, etc.
  • Python Xeger: Python library to generate random strings from regular expressions.
  • sre_dump.py: sre_dump lets you dump the re tree back into a regular expression, useful for debugging.
  • inverse regex: given a regular expression string, produces random strings that match the expression.
  • EXREX: a command line tool and python module that generates all - or random - matching strings to a given regular expression and more.

Java

  • Java Xeger: Java library for generating strings that match a specific regular expression.
    Rexlex

.NET

  • Fare - Finite Auutomata and Regular Epressions is an effort to bring a DFA/NFA (finite-state automata) implementation from Java to .NET. There are quite a few implementations available in other languages today. This project aims to fill the gap in .NET. and provides a port of the well established Java library dk.brics.automaton.
  • REX Rex is a simple command-line tool that takes a .NET regex or several regexes and generates strings that match all the regexes (download).

Ruby

  • regexp-examples Extends the Regexp class with the methods: examples (the generals *all strings that will match the given regular expression and random_example (one example).

Go

  • regen a tool to generate random strings from Go/RE2 regular expressions

Javascript

  • randexp.js Create random strings that match a given regular expression.

Perl

  • String::Random Perl module to generate random strings based on a pattern
  • YAPE::Regex Yet Another Parser/Extractor for Regular Expressions

Haskell

  • regex-genex Given a list of regexes, generate all possible strings that matches all of them.

C++

  • regxstring Random String Generator based on Regular Expression

Code beautifier & Syntax Highlither, Regex Editor (WIP)

Editor

https://www.regexbuddy.com/m/index.html?wlr=1
http://www.ultrapico.com/Expresso.htm https://marketplace.visualstudio.com/items?itemName=GeorgyLosenkov.RegexEditorLite Tester Extension for VS 2017, 2019

Related Topics

.htaccess tester

JsonPath Regex

Regex in JsonPath is not a universal feature and dependent on the actual implementation and the language capabilities.

  • Goessner's JavaScript JSONpath base-implementation: requies a JS-script eval workaround, e.g.: $..book*[?(/^.*world$/i.test(@.title))] (works in JS-based JSONPath-Plus as well)

  • JSONPath-Plus A fork of Goessner's JSONPath script, uses @.match(/../) e.g. $..*[?(@title.match(/orld$/i))]

  • Most comon opton: uses Ruby/Perl regex operator: =~ left matches a regular expression [?(@.name =~ /foo.*?/i)] supported by a number of implementations in different langauges. See cburger's regex filter comparison.

  • Java Jayway JsonPath implementation,

    • Jayway JsonPath Evaluator Jayway JsonPath online tester; allows to swith to Goessner and other outdated implementations too;
  • Python jsonpath-ng implementation, also uses =~ but quotes instead of /../ to wrap the regex $[?(@.Worker =~ ".*880099.*")]; requires to use from jsonpath_ng.ext import parser (there is no only tester I am aware off, repl.it)

  • Almost no implementation support defining a regex filter based on a member $[?(@.name=~/@.pattern/)], see here.

  • Finally, a large number of implementations simply do not support regex filtering (see cburgmer above), e.g.

  • flow/jsonpath A PHP fork of Goessner's JSONPath script; PHP implementations notably does not support regex filtering.

    • JSONPath Tester allows to choose between PHP implementations of JSONPath created by Gössner and Flow Communications.

MS Office Wildcards

Finding and replacing characters using wildcards
OfficeToolTips: Using wildcards & Office Support

References

Comparison

https://www.regular-expressions.info/refadv.html

Character classes

https://www.regular-expressions.info/refcharclass.html

Perl

Python

ICU

Javascript

Alternatives

  • JavaScript Xeger more expressive regular expressions for JavaScript (i.e. sort of an alternative input language) Note: Despite the name, this is not a reverse regex string generator.

.NET/C#

C++

R

re2

  • Regular expression syntax accepted by Google/RE2 (also lists some syntax accepted by PCRE, PERL, and VIM) as avialable in many Google products (Sheets, Docs, Analytics, etc.) text version

Lua Patterns

Alternatives:

  • lrexlib, a multi-flavor regex library
  • LPeg, a powerful text parsing library for Lua based on Parsing Expression Grammar. It offers functions to create and combine patterns in Lua code, and also a language somewhat like Lua patterns or regular expressions to create small parsers.

Linux Text Processing Toolbelt

awk

sed

Tutorials

https://regexone.com/
https://www.hackerrank.com/domains/regex
http://troubleshooters.com/codecorn/littperl/perlreg.htm

Quizzes

https://regexcrossword.com/
https://github.com/firasdib/Freenode-regex-quiz/blob/master/quiz.txt

Internals

How a Regex Engine Works Internally Regular Expressions: Implementations and running times

Performance recommendations and best practices

https://www.regular-expressions.info/catastrophic.html
https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices
http://userguide.icu-project.org/strings/regexp#TOC-Performance-Tips

Comparision

Comparison of regular expression engines: Libraries, Languages, Features
Regular expression speed comparison
Performance comparison of regular expression engines

Perl Regex One-Liners

http://www.catonmat.net/blog/perl-one-liners-explained-part-six/
http://www.rexegg.com/regex-perl-one-liners.html

State Machine Compile, Lexer, Parser Generator

  • Ragel: compiles executable finite state machines from regular languages.

Research

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment