By far, the best tool for the job is RegExr.

The link above will take you to the online version, which is awesome and definitely the best RegEx tool I've ever used.

If you're looking for something you can install in Ubuntu, then try the desktop version, which is an Adobe Air application:

Answer from Nathan Osman on askubuntu.com
🌐
Regex101
regex101.com β€Ί r β€Ί hT2rL8 β€Ί 1
regex101: python regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
Pythex
pythex.org
Pythex: a Python regular expression editor
Pythex is a real-time regular expression editor for Python, a quick way to test your regular expressions.
Discussions

Regex generator
Sounds like you're looking for something like grex . Mind you, this does not save you from learning about regular expressions. Itβ€˜s more of a supporting tool. More on reddit.com
🌐 r/learnpython
5
2
February 3, 2023
Random data generator matching a regex in python - Stack Overflow
In python, I am looking for python code which I can use to create random data matching any regex. For example, if the regex is \d{1,100} I want to have a list of random numbers with a random length More on stackoverflow.com
🌐 stackoverflow.com
How to create a regex pattern
I want to make a refuges pattern that matches a string if it starts with one character,X, and ends with another character, y. More on discuss.python.org
🌐 discuss.python.org
0
October 7, 2022
Does a regular expression generator exist?
I'm not sure I understand you question but https://regex101.com/ will be definitely helpful even if it doesn't reply to your spec. Outside of that, where are you getting the information from and how is it displayed ? Their is probably better way to handle it than that. Give us a sample. More on reddit.com
🌐 r/learnpython
7
3
June 29, 2018
🌐
GitHub
github.com β€Ί maojui β€Ί Regex-Generator
GitHub - maojui/Regex-Generator: NCTU Evolutionary Computation Project
Regex Guide - Plain Text to Regex Generator.
Starred by 38 users
Forked by 6 users
Languages Β  Python 80.7% | HTML 19.3%
🌐
Regex101
regex101.com
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
Python documentation
docs.python.org β€Ί 3 β€Ί library β€Ί re.html
re β€” Regular expression operations
4 days ago - Source code: Lib/re/ This module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings ( str) as well as 8-...
Find elsewhere
🌐
Regex Generator
regex-generator.olafneumann.org
Regex Generator - Creating regex is easy again!
A tool to generate simple regular expressions from sample text. Enable less experienced developers to create regex smoothly.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί regex
Python RegEx (With Examples)
In this tutorial, you will learn about regular expressions (RegEx), and use Python's re module to work with RegEx (with the help of examples).
🌐
Debuggex
debuggex.com
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.
Test your regex by visualizing it with a live editor. JavaScript, Python, and PCRE.
🌐
Tree-sitter
tree-sitter.github.io
Tree-sitter
If you aren't redirected automatically, please go to https://tree-sitter.github.io/tree-sitter/
🌐
RegExr
regexr.com
RegExr: Learn, Build, & Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).
🌐
Python-Fiddle
python-fiddle.com β€Ί tools β€Ί regex
Online Python Regex Playground
The re module provides support for regular expressions, making it straightforward to incorporate regex functionality into your Python scripts.
Top answer
1 of 3
4

Two Python libraries can do this: sre-yield and Hypothesis.

  1. sre-yield

sre-yeld will generate all values matching a given regular expression. It uses SRE, Python's default regular expression engine.

For example,

import sre_yield
list(sre_yield.AllStrings('[a-z]oo$'))
['aoo', 'boo', 'coo', 'doo', 'eoo', 'foo', 'goo', 'hoo', 'ioo', 'joo', 'koo', 'loo', 'moo', 'noo', 'ooo', 'poo', 'qoo', 'roo', 'soo', 'too', 'uoo', 'voo', 'woo', 'xoo', 'yoo', 'zoo']

For decimal numbers,

list(sre_yield.AllStrings('\d{1,2}'))
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99']
  1. Hypothesis

The unit test library Hypothesis will generate random matching examples. It is also built using SRE.

import hypothesis
g=hypothesis.strategies.from_regex(r'^[A-Z][a-z]$')
g.example()

with output such as:

'Gssov', 'Lmsud', 'Ixnoy'

For decimal numbers

d=hypothesis.strategies.from_regex(r'^[0-9]{1,2}$')

will output one or two digit decimal numbers: 65, 7, 67 although not evenly distributed. Using \d yielded unprintable strings.

Note: use begin and end anchors to prevent extraneous characters.

2 of 3
2

If the expressions you match do not have any "advanced" features, like look-ahead or look-behind, then you can parse it yourself and build a proper generator

Treat each part of the regex as a function returning something (e.g., between 1 and 100 digits) and glue them together at the top:

import random
from string import digits, uppercase, letters

def joiner(*items):
    # actually should return lambda as the other functions
    return ''.join(item() for item in items)  

def roll(item, n1, n2=None):
    n2 = n2 or n1
    return lambda: ''.join(item() for _ in xrange(random.randint(n1, n2)))

def rand(collection):
    return lambda: random.choice(collection)

# this is a generator for /\d{1,10}:[A-Z]{5}/
print joiner(roll(rand(digits), 1, 10),
             rand(':'),
             roll(rand(uppercase), 5))

# [A-C]{2}\d{2,20}@\w{10,1000}
print joiner(roll(rand('ABC'), 2),
             roll(rand(digits), 2, 20),
             rand('@'),
             roll(rand(letters), 10, 1000))

Parsing the regex would be another question. So this solution is not universal, but maybe it's sufficient

🌐
W3Schools
w3schools.com β€Ί python β€Ί python_regex.asp
Python RegEx
RegEx can be used to check if a string contains the specified search pattern. Python has a built-in package called re, which can be used to work with Regular Expressions.
🌐
Mimo
mimo.org β€Ί glossary β€Ί python β€Ί regex-regular-expressions
Python Regex: Master Regular Expressions in Python
Learn how to use Python regular expressions (regex) for matching, searching, and manipulating text. Explore examples of Python regex for validation, data extraction, and more. Perfect for beginners and intermediate programmers!
🌐
LeetCode
leetcode.com β€Ί problems β€Ί regular-expression-matching
Regular Expression Matching - LeetCode
Can you solve this real interview question? Regular Expression Matching - Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: * '.' Matches any single character. * '*' Matches zero or more of the preceding element.
🌐
Python.org
discuss.python.org β€Ί python help
How to create a regex pattern - Python Help - Discussions on Python.org
October 7, 2022 - I want to make a refuges pattern that matches a string if it starts with one character,X, and ends with another character, y.
🌐
Pyregex
pyregex.com
PyRegex
PyRegex is a online regular expression tester to check validity of regular expressions in the Python language regex subset.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί does a regular expression generator exist?
r/learnpython on Reddit: Does a regular expression generator exist?
June 29, 2018 -

For example, given a list of characters*, is there a tool to generate a regular expression that matches items in the list?

Looking to use something like that to define the 'pattern' property in json draft 4 specs. Python style regex is fine.

(*) edited to be more general.

Sample data:

['XCP', 'STEEM', 'BTM', 'PINK', 'NXT', 'BTS', 'ETH', 'MAID', 'SYS', 'BCY', 'PASC', 'XEM', 'NAV', 'DCR', 'BTC', 'BLK', 'POT', 'ARDR', 'VRC', 'XRP', 'RIC', 'AMP', 'REP', 'XVC', 'DGB', 'GAME', 'PPC', 'LBC', 'GNT', 'GNO', 'XBC', 'FLO', 'OMG', 'NXC', 'BCH', 'DASH', 'EMC2', 'GRC', 'ETC', 'XPM', 'LSK', 'BURST', 'EXP', 'RADS', 'FLDC', 'DOGE', 'CVC', 'LTC', 'BCN', 'SBD', 'GAS', 'CLAM', 'HUC', 'FCT', 'VTC', 'XMR', 'VIA', 'STRAT', 'NEOS', 'SC', 'ZEC', 'BTCD', 'NMC', 'OMNI', 'STR', 'STORJ', 'ZRX']

I wouldn't expect the tool to be perfect due to the number of possibilities. I'm just looking for something that will help me identify the patterns quickly and possibly spot outliers. This would not be used in place of proper validation. Would also be interested in comparing the output of a regex generator to my patterns or something that refactors existing regular expressions in simplest terms - for learning purposes.

[A-Z]{2,6} 100%

[A-Z]{3,6} 98%