Regex Net — Regex

Net text with regex: 10 levels of anchors, quantifiers, groups and lookahead. The most practical regex game around. 10 levels, right in the browser.

What you learn in this game

A regular expression (regex) is a pattern for finding text. At Mr. Ujang’s fish pond the pattern is a net: every block you tap knots in one stretch, left to right. When the pond is let out, the fish swim to the net one at a time. A label that matches the pattern is held, and the part of it the net holds lights up. One that does not match goes through to the lower pond.

A character class [...] matches one character from the list inside it. [aiu] = one letter a, i, or u. [0-9] = one digit. Inside the brackets most symbols lose their special meaning: [.] is just a dot.

A quantifier says how many times what comes before it repeats: {3} exactly three times, {2,4} two to four times. An anchor takes no characters: ^ points at the start of the text, $ at its end.

A group ( ) binds several characters into one unit that can be repeated, and keeps the part it matched. In Mr. Ujang’s net a group is a pocket: the stretch between the two brackets bellies out and keeps what it catches.

Every knot so far comes together in one net. Remember the difference: . with no backslash = any character, \. = a dot only. It matters for emails, web addresses, and times.

What the levels ask

  1. Mrs. Yanti orders every nila (tilapia) for the fried fish at her food stall. Knot a net that holds every fish whose label contains that word, anywhere in it, and lets every other fish through to the lower pond.
  2. Mrs. Ida shares fish out to the two twin houses at the end of the lane: 4A and 5A. Hold the fish whose label names one of those houses, and hold the house number. Other houses go through.
  3. Mrs. Sari writes the orders on her stall’s board. Mr. Ujang packs the fish by the number on each label, so the net must hold the number whole: twelve, not one. A label with no digit 0 to 9 goes through, and Mrs. Sari sees to it herself.
  4. Ms. Wulan sends Mr. Ujang’s spiced fish to town. The post office form only takes a label that is exactly five digits: no fewer, no more, no other writing, and no Enter.
  5. The neighbourhood head shares out grilled fish to the Thursday night watch. On the night watch roster, that watch’s line starts with Kamis (Thursday). Hold the lines that start with that day; the neighbourhood head only ticks the day, so the net holds the day’s name alone. A line that names Kamis in the middle, or starts with another word, goes through.
  6. Mrs. Ijah orders lele (catfish) for the Beach Stall, and lele dumbo is priced apart. Mr. Ujang writes down what the net holds: a dumbo label must be held up to dumbo, any other catfish just lele. Other fish go through.
  7. Grandpa Joyo marks the fish of each night watch with its alarm drum beat: tok struck again and again. Hold the fish whose label has that beat, and the net must hold every stroke in a row. The net’s pocket keeps what it catches.
  8. Rara copies the numbers on the stall’s board into a phone book, filed by first letter. A line that does not start with a digit already has a name: hold it, and the net holds its first character only. A line that starts with a digit has no name yet and goes through.
  9. Mr. Harun takes the fish to the town market on the seven fifteen bus. People write the time all sorts of ways: a dot, a colon, or a space between hour and minutes. Hold every label for that bus and hold its time. Other times, ticket numbers, and a time broken onto a new line go through.
  10. Mr. Piksel helps Mr. Ujang send the receipts by email. Hold the labels that contain the shape name, @, domain, dot, ending (each part letters, digits, or underscores), and hold the address only. An unfinished one goes through.