Code challenges that involve the use of regular expressions.

learn more… | top users | synonyms

17
votes
4answers
3k views

Meta regex golf

In the spirit of this xkcd Write a program that plays regex golf with arbitrary pairs of lists. The program should at least attempt to make the regex short, a program that just outputs ...
15
votes
4answers
1k views

Match strings whose length is a fourth power

Within the scope of this question, let us consider only strings which consist of the character x repeated arbitrary number of times. For example: <empty> x xx xxxxxxxxxxxxxxxx (Well, ...
8
votes
2answers
555 views

Compile Regexes

In this task you have to write a program that reads a regular expression and generates another program that outputs whether an input string is accepted by that regular expression. The output must be a ...
8
votes
4answers
606 views

Generate regular expressions for matching natural numbers between `m` and `n`

The type of regular expression is PCRE. Write a program that output a valid PCRE such that it matches all natural numbers between m and n and does not match anything else. No leading zeros are ...
62
votes
40answers
7k views

Cops and Robbers: Regex Golf

Note: This challenge is now closed. Any future cops' submission will not be considered for the accepted answer. This is to ensure that no one can post a very simple regex in the future that only ...
54
votes
24answers
12k views

Shortest unmatchable regular expression

Your mission is to write the shortest valid regular expression that no string can match, empty string included. Submissions must have this form ("literal notation"): /pattern/optional-flags ...
9
votes
3answers
1k views

Self-matching regex

Write a non-trivial regex that matches itself. For example, #.*$ will match a comment outside of a string in python until the end-of-line, and also matches itself in perl regex syntax. Rules: The ...
11
votes
2answers
1k views

Regex in reverse - decompose regular expressions

The Problem I have a bunch of regular expressions that I need to use in some code, but I'm using a programming language that doesn't support regex! Luckily, I know that the test string will have a ...
4
votes
2answers
265 views

Regex for Finding Radioactive Elements

Find the shortest regex that matches all radioactive elements and nothing else in the Periodic Table of Elements. Radioactive Elements ...
4
votes
2answers
277 views

Negative Regexp

Write the shortest function that takes one string, and returns a regular expression that matches anything EXCEPT the input string, in parenthesis. Escape necessary characters like Perl quotemeta. ...
3
votes
2answers
150 views

Reverse Regular expressions [closed]

The idea here is to write a little segment that will spit out regular expression patterns when given a string that matches them. As you might have guessed, this will be a popularity contest, and I'll ...