Questions tagged [regular-expression]

Code challenges that involve the use of regular expressions.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
125 views

What is the shortest regex for the name "SAMUEL"? [duplicate]

Suppose that someone is trying to access records from a database on swim lessons. At one point during the conversation, a customer says, "The student's name is Samuel Doe". However, the name ...
Samuel Muldoon's user avatar
0 votes
0 answers
67 views

What is the shortest regular expression (REGEX) you can create for variants on the name "ELLEN"? [duplicate]

Imagine a partially automated customer service phone line. At one point during the conversation, a customer says, "My name is Ellen Doe". However, the name on record is spelled differently. ...
Samuel Muldoon's user avatar
0 votes
1 answer
141 views

What is the shortest regular expression (REGEX) you can create for file extensions for image formats? [duplicate]

What is the shortest regular expression (REGEX) you can create for file extensions for all of the following image file formats (photographs, paintings, sketches, and drawings)? ...
Samuel Muldoon's user avatar
8 votes
5 answers
2k views

What is the shortest regex for the month of January in a handful of the world's languages?

What is the shortest regular expression equivilant to the following? ...
Samuel Muldoon's user avatar
6 votes
3 answers
307 views

Write a regex that would increment a 2-digit hexadecimal number

Your regex will receive a string of the form !XX! #<extra> where X is any hexadecimal digit (0-9 and A-F capital letters ...
Itay123's user avatar
  • 71
15 votes
3 answers
341 views

Is it a bigger regex?

You are given two regexes and your task is to determine if the strings matched by the first regex are a subset of the strings matched by the second regex. For this we are going to use a limited ...
AnttiP's user avatar
  • 7,828
6 votes
2 answers
291 views

Generate Matching Regexes

Write a program that takes two lists of strings and generates a javascript regex that fully matches all the strings in the first list and matches none of the strings in the second list. To be specific ...
user197974's user avatar
  • 1,161
14 votes
9 answers
1k views

Convert Regex to Mask

From my CMC. Given a regex and a non-empty printable ASCII text, return one bit per character in the text, indicating the positions of beginnings of non-overlapping matches, and also the positions of ...
Adám's user avatar
  • 29.9k
4 votes
2 answers
693 views

Give the minimum Levenshtein distance to a string that matches the regex

Your task, at the moment that you choose to accept it, is to write a program that, when given a string and a PCRE-regex, calculates the minimum Levenshtein distance to another string that matches the ...
user avatar
5 votes
2 answers
1k views

Generate the shortest regex to match these but not those [closed]

Challenge Given two lists of strings where each string is of length 50 and each list is also of length 50 generate the shortest regex you can that fully matches all the strings in the first list and ...
user197974's user avatar
  • 1,161
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
9 votes
1 answer
183 views

Are We Fast And Furious? [closed]

There are currently nine feature length films in the core Fast & Furious/The Fast and the Furious media franchise, a series of films about bald men scowling and driving cars very fast. The names ...
lowercasename's user avatar
11 votes
1 answer
235 views

Generating minimal regular expression character classes

Background Character classes are a standard way to indicate a set of characters to match in regular expressions. For example, the class [ab] matches a or b, ...
Uri Granta's user avatar
  • 2,959
11 votes
2 answers
2k views

Distinguish English and Spanish with regular expressions

The task is to to compete for the shortest regex (in bytes) in your preferred programming language which can distinguish between English and Spanish with minimum 60%...
GirkovArpa's user avatar
8 votes
2 answers
8k views

Resource for generating shortest regex given a list of strings

I'm looking for a program such that, given a finite list of strings, can find short regexes to match exactly all of them and nothing else. Since there are multiple languages that express regexes ...
ghosts_in_the_code's user avatar
6 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
  • 14k
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
13 votes
1 answer
423 views

Duct Tape a Regex Decider

Your task is to create a program that determines whether a given string is a valid regular expression or not using code snippets sourced from sites on the StackExchange network. For the purposes of ...
Beefster's user avatar
  • 9,891
5 votes
2 answers
401 views

Regex golf and ccTLDs, hooray!

Write a regex that only matches valid country code top level domains (ccTLDs). Your regex must match both the domains with the dot and without the dot (it must match tv and .tv). Any domain that is ...
AndrewTheCodegolfer's user avatar
1 vote
0 answers
78 views

Print everything which a regular expression matches [duplicate]

Modern regular expressions (regexes) have many features (\d, {n,m}, \1, etc.), but to define ...
pommicket's user avatar
  • 3,129
7 votes
1 answer
240 views

Insert commas into numbers [closed]

Write a program that reads a string, and inserts commas to divide large numbers in groups of 3. i.e. 10000 => 10,000. It should 'fix' incorrectly formatted numbers as described below. It must work ...
Brandon's user avatar
  • 139
-3 votes
1 answer
779 views

Regex only base64 decoder [closed]

Write a regular expression substitution string which can base64 decode a string using only a regular expression engine built into the language. Eg: ...
Paradoxis's user avatar
-2 votes
3 answers
291 views

FreeChat Online [closed]

FreeChat Online It is 1985, and you are a humble Russian potato farmer. Sadly, your glorious homeland is going through a time of crisis and it needs your help! The KGB, with the "assistance" ...
Michael's user avatar
  • 131
17 votes
6 answers
1k views

The Binary Fences

Input: An integer n in the range 2 <= n <= 10 A list of positive integers Output: Convert the integers to their binary ...
Kevin Cruijssen's user avatar
1 vote
2 answers
2k views

Regular Expression to find a pangram [closed]

Awhile back I encountered a simple programming puzzle to determine whether a string was a pangram, or a perfect pangram. (Although it's worth noting that this particular challenge gave a different ...
soapergem's user avatar
  • 263
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
14 votes
1 answer
1k views

Regex for multiples of 9

It is easy to describe a finite state machine that recognizes multiples of 9: keep track of the digit sum (mod 9) and add whatever digit is accepted next. Such a FSM has only 9 states, very simple! By ...
Alex Meiburg's user avatar
6 votes
3 answers
289 views

Create a regex to match a given range of integers in a given radix

Task Write a program/function that, given three integers n,a,b prints a regular expression which matches all of the base-n integers from ...
Josh Withee's user avatar
27 votes
3 answers
3k views

A regex to match three consecutive integers iff the third integer is the sum of the first two

Write a regular expression which matches a given string consisting of three non-negative, space-separated integers if and only if the last integer is the sum of the previous two. Answers may be for ...
Josh Withee's user avatar
19 votes
2 answers
661 views

Regex: Match an egalitarian series

Introduction I don't see many regex challenges on here, so I would like to offer up this deceptively simple one which can be done in a number of ways using a number of regex flavours. I hope it ...
jaytea's user avatar
  • 507
8 votes
6 answers
650 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
4 votes
4 answers
511 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
82 votes
11 answers
19k views

Regex, Paper, Scissors, Lizard, Spock

Warm up: Regex, Paper, Scissors This is the challenge I originally wanted to post, before realising that some very short solution exist. Nevertheless, it can be an interesting problem to think about ...
Martin Ender's user avatar
7 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,670
8 votes
1 answer
742 views

Regex that matches everything but itself

You must make a regex that matches everything except itself. For example, PPCG must not match PPCG, but must match everything ...
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
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
2 votes
0 answers
140 views

Find letter-similar words in a word list [closed]

(I am not sure that this is the best place to put this question, but I will give it a shot. Forgive me if it is improper. This is just a fun project with which I am tinkering and I am looking for ...
user173897's user avatar
19 votes
1 answer
681 views

Make a regex polyglot

Write a regex that works in at least 2 regex flavors (or versions), and match a different string in each flavor (or version) it is running in. The strings to be matched in this challenge are the ...
jimmy23013's user avatar
  • 36.9k
15 votes
9 answers
2k views

The codegolf object

Imagine this, we have an environment with a global scope containing just a single object, called codegolf. This object has a single child called ...
Bassdrop Cumberwubwubwub's user avatar
17 votes
3 answers
1k views

Match the permutations!

Your challenge is to create a regex that matches every string permutation of itself, and nothing else. The match must also be case-sensitive. So, for example, if your regex is: ...
clismique's user avatar
  • 6,972
-3 votes
1 answer
514 views

A regex to satisfy the grammar police (there vs. their vs they're)

We've all been burned by the grammar police on the internet. What we need is a regex that can be used in place of "there", "their", and "they're". This would shift burden of grammar parsing from the ...
Michael Whatcott's user avatar
16 votes
4 answers
964 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,379
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
6 votes
6 answers
846 views

Is case sensitivity important? Part II: reality check

In this question Tom learned that, in general, there are many motivations to choose to include case sensitivity in his programming language, because the possible combinations for a variable name are ...
user6245072's user avatar
2 votes
2 answers
672 views

Check if a pattern appears in a DNA sequence

In a project I am working on, I am checking to see if certain DNA sequences appear in certain genes in E. coli. I have written a program in Java that performs the below features. However, since I ...
Arcturus's user avatar
  • 7,349
20 votes
5 answers
1k views

Shortest simple regex matching a binary word

Task Define a simple regex as a non-empty regular expression consisting only of characters 0 and 1, grouping parentheses ...
Lynn's user avatar
  • 68.1k
10 votes
3 answers
449 views

RegEx-golf: match all contents in a string

Your task is to write a RegEx that matches everything inside strings. A string is defined as everything surrounded by (but not including) two unescaped ". A ...
Leaky Nun's user avatar
  • 49.6k
2 votes
1 answer
305 views

Find the last three words of each paragraph if they are shorter than 20 characters in total

Based on my SO question, but more specifically: Find a RegEx such that, given a text where paragraphs end with an empty line (or $ at the very end), match the up ...
Tobias Kienzler's user avatar
9 votes
2 answers
460 views

Inverse regex of compound interest

Koronkorko is the Finnish word for compound interest. We don't want compound interest in our strings, so let's find the shortest possible regular expression to exclude it. Given a string consisting ...
guest's user avatar
  • 101