Code challenges that involve the use of regular expressions.

learn more… | top users | synonyms

16
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
535 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
588 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 ...
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 ...
10
votes
1answer
885 views

Implement PCRE in your language.

Note: After trying this myself, I soon realized what a mistake this was. Therfore, I am modifying the rules a bit. The minimum required functionality: Character classes (., \w, \W, etc.) ...
7
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 ...
10
votes
2answers
916 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
248 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
274 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
149 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 ...