Regex

This is a README.adoc file. The original repository is located here.

Regex

Fenrir ID: regex
Branch: regex
Points: 30

Globs (10 points)

Save your answers to the answer.properties file. Each answer is a glob pattern which describes the required files.

The solution must be a single glob pattern!

Bash’s globstar option is on during this part.

Task 1 (3 points)

Files stored directly in a directory whose name starts with logs-2026-. The file’s extension must be .txt.

Task 2 (3 points)

Files stored in the logs-2025 directory with .txt extension.

Task 3 (4 points)

Files with .txt extension which are stored in a directory B13-60_ or B13-61_ (_ is any symbol) that is data's subdirectory.

Sed & grep (13 points)

Save the answers to the sed-grep.sh file.

You must use grep or sed only (you are free to combine them in pipelines)!

Task 1 (2+2 points)

You are provided with a log file. The records follow this format:

YYYY-MM-DD HH:MM:SS [TID] LEVEL CLASSNAME - MESSAGE
  • TID  —  Thread ID, a sequence of symbols without space characters

  • CLASSNAME  —  Fully qualified name, a sequence of word symbols without space characters

  • MESSAGE  —  A nonempty sequence of symbols. May contain space characters but no newlines

  • LEVEL  —  One of INFO, DEBUG, WARN, ERROR, FATAL

The file may contain malformed records: you must ignore them. The path to the file is passed via TEST_DATA env variable.

You don’t have to validate date’s or time’s correctness (e.g. 8888-88-88 is a valid date).

Implement the get_class function which prints all CLASSNAMEs of all valid INFO logs.

Implement the get_ip function which prints all IPs mentioned in the valid logs.

IP is four numbers from 0 to 255 separated by dots. It is assured that invalid IPs (e.g. 333.100.200.200) are not present throughout the logs.

Task 2 (9 points)

Implement the get_name function: it takes a JSON string which follows this format:

{
  "name": ..,
  "repo": {
    "id": ..,
    "name": ..,
    "nam": [ { "name": .. }, .. ]
    "owner": {
      "name": ..,
      "id": ..
    }
  }
}

Everything but id is a string, id is an integer. As JSON spec allows, space characters may or may not appear. Moreover, the fields might be rearranged: there are no order guarantees.

The function must print owner's name. E.g. …​ "owner": {"name":"qwe"…​ must output a qwe string.

Stdlib regex (7 points)

C++ solution: regex.cc
Java solution: Regex.java

You must use stdlib’s regexes. No direct data manipulation is allowed!

Task 1 (3 points)

Implement the parseLog function. You are provided with an unstructured string, the only guarantees are:

  • surname is preceded by sn: and is double-quoted

  • name is preceded by nm: and is double-quoted

  • both attributes consist of word symbols

You must return an optional of NAME-SURNAME if possible. Otherwise, return the empty optional. E.g. qwe sn:"u" nm:"o" po must be mapped to Optional.of("o-u") while qwe sn:"u" nm:"opo to Optional.empty().

Task 2 (4 points)

Implement the getNumbers function. It takes a multi-line string and returns a list of European numbers, mentioned in the input.

A European number has the format +CODE NUMBER:

  • CODE  —  either 7 or two/three digits that start with 3 or 4

  • NUMBER  —  from eight to ten digits

  • CODE and NUMBER might be separated by a space

Questions

  • What is globstar and why is it required?

  • How to merge several strings into one glob pattern?

  • What is the difference between grep's -E and -P flags?

  • How to match a pattern over a multi-line string in grep?

  • How to extract a substring using regexes?

  • How to mark word borders?

The project is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

© 2026-present Iwan Kalinin <koefic.cien@gmail.com>