Tagged Questions

Code challenges that involve the use of regular expressions.

learn more… | top users | synonyms

8
votes
2answers
288 views

Python: I wish I was PHP

There's an old story about a stonecutter who was never satisfied with what he was. He wished he could become the sun, and so he was. Blocked by the clouds, he wished to be - and became - a cloud. When ...
56
votes
40answers
6k views

Cops and Robbers: Regex Golf

Note: The deadline for submitting a regex is 01/11/2014 00:00:00Z. Any cops' submission after that will not be considered for the accepted answer. This is to ensure that no one can post a very ...
31
votes
3answers
3k 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, ...
6
votes
1answer
406 views

Regex that matches any regex [duplicate]

Your task is to write a regular expression that matches any valid regular expression and no invalid expression. You may pick any regex flavour for your answer, but you have to match regular ...
10
votes
2answers
934 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 ...
5
votes
0answers
377 views

Complement a Regular Expression

Given a regular expression as input, output its complement. If the given regular expression matches a string, its complement should not match it, and the regex: (regex given)|(complement) should match ...
-1
votes
1answer
131 views

POSIX reg. exp to test the divisibility by 9

Write the shortest POSIX-form regular expression that matches only non-negative integers divisible by 9. The non-negative integer should be given in base 10.
19
votes
11answers
873 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 ...
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 ...
3
votes
1answer
717 views

Match strings whose length is isolated prime

Isolated prime definition from Wikipedia: An isolated prime is a prime number p such that neither p − 2 nor p + 2 is prime. In other words, p is not part of a twin prime pair. For example, 23 is ...
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, ...
13
votes
2answers
318 views

Singular or plural?

Here is a list of 30 English nouns in their singular and plural form. Your job is simply to write the shortest regular expression that matches all the nouns in one form and none in the other (easy, ...
0
votes
4answers
191 views

Regex - Match half of the strings

Okay, the challenge is that you have to write a regex that matches half of all strings. Some rules to clarify: For ANY string length(>0), if I permute all strings(of that length), exactly half of ...
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 ...
2
votes
3answers
286 views

Regex for Finding Non-Radioactive Elements

Find the shortest regex that matches all non-radioactive elements and nothing else in the Periodic Table of Elements. This is the inverse of Regex for Finding Radioactive Elements Radioactive ...
4
votes
2answers
252 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 ...
19
votes
5answers
836 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? ...
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 ...
0
votes
2answers
642 views

Make a regex that matches certain binary numbers [closed]

Your task is to create a regular expression that matches most binary numbers with an even number of 0s and an odd number of 1s (e.g. "101100011"). The full criteria for the regex are: matches 90% ...
8
votes
4answers
595 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 ...
2
votes
1answer
311 views

Convert Regexes

Suppose you have existing regexes you wish to compile using one of the submissions to Compile Regexes. In as few characters as possible, write a program that: accepts an existing regex as input, as ...
8
votes
2answers
538 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 ...
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 ...
33
votes
4answers
8k views

Hard code golf: Regex for divisibility by 7

Matthias Goergens has a 63,993-character regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution (xx|xy|yx|yy rather than [xy]{2}) and other ...
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. ...
10
votes
1answer
889 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.) ...