Questions tagged [regular-expression]

Code challenges that involve the use of regular expressions.

Filter by
Sorted by
Tagged with
33 votes
7 answers
5k 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: ...
n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳'s user avatar
30 votes
1 answer
2k 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: ...
EMBLEM's user avatar
  • 2,381
33 votes
4 answers
6k 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 ...
Manishearth's user avatar
19 votes
2 answers
1k 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 ...
FUZxxl's user avatar
  • 10.1k
19 votes
3 answers
5k 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 ...
Doorknob's user avatar
  • 71.5k
378 votes
1 answer
118k 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, ...
Dylan Madisetti's user avatar
161 votes
57 answers
43k views

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

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 ...
Athari's user avatar
  • 2,343
87 votes
6 answers
42k 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 (...
Charles's user avatar
  • 2,771
52 votes
17 answers
10k 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 ...
Martin Ender's user avatar
42 votes
5 answers
20k 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 ...
Martin Ender's user avatar
18 votes
1 answer
4k views

Regex validating regex [closed]

Build a regex that will accept a regex string as input and check if it's valid. Basically, your regex should be able to validate itself. (Any invalid regex should not be validated, so you can't use <...
Mateen Ulhaq's user avatar
  • 1,973
76 votes
40 answers
11k views

Cops and Robbers: Reverse 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 ...
Martin Ender's user avatar
65 votes
23 answers
15k 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"): ...
xem's user avatar
  • 5,835
41 votes
51 answers
7k views

Cops: Make a regex - Make a snake

This is the cop's thread. The robber's thread is here. Write a code that takes an input n and creates a n-by-n "snake matrix". A snake matrix is a matrix that ...
Stewie Griffin's user avatar
38 votes
10 answers
4k 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 ...
algorithmshark's user avatar
16 votes
4 answers
965 views

Match the Stack Exchange URLs

Prologue After installing an anti-XSS browser extension, Stack Snippets suddenly stopped working all across the Stack Exchange network. I could no longer learn from Stack Overflow, see working demos ...
wizzwizz4's user avatar
  • 2,377
42 votes
42 answers
5k views

A Different Kind of Meta Regex Golf

Notice: Following popular demand I have slightly relaxed the rules: The maximum regex size grows by 1 byte every 5 answers. Answer N may use up to 29 + ⌈N/5⌉ bytes. The score of each answer ...
Martin Ender's user avatar
37 votes
3 answers
1k views

HexaRegex: A Tribute to Martin Ender

Martin Ender recently hit 100K, and has come up with some pretty awesome languages. We're going to have a bit of fun with one of them, Hexagony (and a bit of regex for Retina) As a brief overview, ...
Nathan Merrill's user avatar
36 votes
1 answer
2k views

Complement a POSIX Extended Regular Expression

Given a POSIX Extended Regular Expression as input, output its complement (also a POSIX ERE). If the given regular expression matches a string, its complement should not match it, and the regex: ...
Justin's user avatar
  • 21.2k
26 votes
7 answers
2k views

Recognize most smaller primes with a regex

This time, you are working on a regex. Your regex is meant to approximately full-match the base-10 representations of primes \$0 \le p < 1000\$, while ignoring any non-numeric string or composite ...
AndrewTheCodegolfer's user avatar
25 votes
2 answers
1k 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 ...
Ell's user avatar
  • 7,697
23 votes
11 answers
1k 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: ...
GOTO 0's user avatar
  • 822
22 votes
13 answers
2k views

Check if simple regex matches string

A simple regex is either: _ (which matches the empty string) Any lowercase letter a to z (...
user avatar
22 votes
41 answers
4k views

Robbers: Crack the regex - Make a snake

This is the robber's thread. The cop's thread is here. A snake matrix is a square matrix that follows this pattern: 3-by-3: 1 2 3 6 5 4 7 8 9 and 4-by-4: ...
Stewie Griffin's user avatar
20 votes
8 answers
16k views

Remove single line and multiline comments from string

Goal Using the programming language of your choice, write the shortest program to eliminate comments from a string representing a C program. Input The string can be taken as any form of input, but ...
Mathieu Rodic's user avatar
19 votes
2 answers
2k views

Complement of a Regex

For the purposes of this challenge, we define a postfix regex dialect with alphabet {1, 0} and the following operations: 1 and <...
Esolanging Fruit's user avatar
18 votes
9 answers
1k 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 ...
Alfredo Diaz's user avatar
16 votes
2 answers
777 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 ...
Crissov's user avatar
  • 439
15 votes
3 answers
4k views

Self-matching regex [closed]

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 ...
Casey Kuball's user avatar
11 votes
4 answers
703 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 ...
qw3n's user avatar
  • 751
9 votes
6 answers
653 views

The greedy regex (cops)

This is the cops' post. The robbers' is here. You make a program and a regex. For most inputs, one of the following happens: the regex doesn't match, and the program returns a falsey value the ...
user avatar
8 votes
1 answer
2k views

Regular expression parser

This task is a classic programming task: Implement a regular expression parser. That is, write a program or function which takes a string describing a regular expression and a candidate string, and ...
celtschk's user avatar
  • 4,680
7 votes
4 answers
3k views

Count regex matches

Your task Given a simple regular expression, you have to count how many strings of length n have a match of length n with the ...
RGS's user avatar
  • 14.1k
5 votes
3 answers
400 views

Negative Regexp [closed]

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 ...
Ming-Tang's user avatar
  • 5,969
5 votes
4 answers
513 views

The greedy regex (robbers)

This is the robbers' post. The cops' is here. Your challenge is to take a cop's post and find an input that the regex matches but the program returns a falsey value. Once you have cracked a cop's ...
user avatar