Code challenges that involve the use of regular expressions.

learn more… | top users | synonyms

24
votes
4answers
4k 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 ...
10
votes
2answers
713 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 ...
142
votes
55answers
33k views

Debunking Stroustrup's debunking of the myth “C++ is for large, complicated, programs only”

Stroustrup has recently posted a series of posts debunking popular myths about C++. The fifth myth is: “C++ is for large, complicated, programs only”. To debunk it, he wrote a simple C++ program ...
69
votes
39answers
8k 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 ...
13
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 ...
64
votes
7answers
24k views

Hard code golf: Regex for divisibility by 7

Matthias Goergens has a 25,604-character (down from the original 63,993-character) regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution ...
30
votes
16answers
4k views

Tips for Regex Golf

Similar to our threads for language-specific golfing tips: what are general tricks to shorten regular expressions? I can see three uses of regex when it comes to golfing: classic regex golf ("here ...
39
votes
5answers
4k views

Adding Numbers with Regex

I want to try a new type of regex golf challenge, which asks you to solve nontrivial computational tasks with nothing but regex substitution. To make this more possible and less of a chore, you will ...
22
votes
4answers
2k 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, ...
12
votes
6answers
2k views

Interpret /// (pronounced 'slashes')

Because we can't get enough of esoteric language golfs, can we? ///—pronounced slashes—is a fun little language based on the s/// regex-replacement function of Perl fame. It contains only ...
8
votes
4answers
864 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 ...
70
votes
1answer
5k views

Regex that only matches itself

There are some pretty cool challenges out there involving regex (Self-matching regex, Regex validating regex) This may well be impossible, but is there a regex that will ONLY match itself? NOTE, ...
24
votes
2answers
624 views

Partial Ordering of Regex Patterns

For the purpose of this challenge, we say that a regex pattern matches a string if the entire string is matched by the pattern, not just a substring. Given two regex patterns A and B, we say that A ...
13
votes
2answers
458 views

ValiDate ISO 8601 by RX

Challenge Find the shortest regex that validates, i.e. matches, every possible date in the Proleptic Gregorian calendar (which also applies to all dates before its first adoption in 1582) and does ...
55
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 ...
24
votes
3answers
851 views

Gotta Match Them All! Write a regex to match the original 151 Pokemon but no subsequent Pokemon

The original 151 Pokemon, in an array format suitable for initializers: ["Bulbasaur", "Ivysaur", "Venusaur", "Charmander", "Charmeleon", "Charizard", "Squirtle", "Wartortle", "Blastoise", "Caterpie", ...
22
votes
5answers
1k views

Regex Golf: Regions of Italy vs. States of USA

We've already got a meta-regex-golf problem as inspired by the xkcd comic But, this regex golf looks fun, too! I want to distinguish between the states of the US and the regions of Italy. Why? ...
12
votes
3answers
2k 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 ...
9
votes
3answers
410 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 ...
21
votes
11answers
973 views

Cross-matching regular expressions

Your task here is to write two regular expressions, each of which matches the other one but does not match itself. Both regular expressions should have this form: /pattern/optional-flags This is ...
18
votes
9answers
900 views

Sum the time durations

Challenge Write the shortest code that can sum all the time durations that appear in the stdin. The program must only consider the strings that match with one of the following patterns and ignore the ...
4
votes
2answers
281 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
163 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 ...