{}const=>[]async()letfn</>var
Development

🧩 Regular expressions: the magic of code search

Sounds like a spell? In fact, regular expressions are a powerful tool that allows you to search, check, and modify text according to a pattern.

К

Kodik

Author

3 min read

🔍 What are regular expressions?

Regular expression is a string describing the search pattern. It consists of symbols and special characters that define what exactly we are looking for.

In simple terms:
👉 it's like smart search mask, which finds what matches a certain structure.

/hello/

This expression will find the word "hello" in any text.

🛠 How does it work?

const text = "Hi, my name is Kodik!";
const result = /Кодик/.test(text);
console.log(result); // true

The .test() method checks Is there a match? with a template. If yes, it will return true.

🔍 Line-by-line analysis:

const text = "Hi, my name is Kodik!";
We create a variable text that stores a regular string. This is our "text" in which we will search for a match.

👉 Inside the line there is the word Кодик — this is what we want to find.

const result = /Code/.test(text);
This is where the most interesting thing happens:

  • /Кодик/ — a regular expression that searches for an exact match of the word Кодик.

  • .test(text) — a method that:

    • accepts the string text

    • checks if there is a match with the template

    • returns true if a match is found, otherwise false

🧠 In our case, the word Кодик is indeed in the text, so the result will be true.

console.log(result); // true
Here we are just displaying the result of the check to the console:

  • If Кодик is found, the console will display true

  • If it wasn't there, it would be false

💬 In other words:

You tell the browser:
"Hey, see if this text contains the word 'Kodik'? If yes, tell me true"

And JavaScript, as a faithful assistant, says: ✅ Yes, there is! — true

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

🧪 Useful constructions

Syntax

What it does

Example

.

Any single character

/c.t/ will find "cat", "cut"

*

Zero or more repetitions

/lo*/ will find "l", "looo"

+

One or more

/lo+/ will find "lo", "loo"

?

0 or 1 time

/colou?r/ — "color" and "colour"

\d

Any number

/\d\d/ — two digits in a row

\w

Letter, number or _

/\w+/ — any word

^

Start of line

/^Привет/

$

End of line

/Кодик!$/

🧠 Example: email verification

const email = "test@example.com";
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
console.log(pattern.test(email)); // true

What's happening:

  • ^ and $ — the beginning and end of the line

  • [^\s@]+ — at least one character other than a space and @

  • @ — must be present

  • \. — dot before the domain (escaped!)

  • + — repetition again

🧠Where are regular expressions used?

💡 Scope of application

📋 What do regulars do

Form validation

They check email, passwords, phone numbers, and other input fields

Find and replace in text

They find templates and replace them with the right ones

Parsing logs, CSV, HTML

Extract the necessary data from rows, tags and structured files

Writing linters and parsers

Help analyze code and find errors or stylistic deviations

Quick search by code or documentation

Find the necessary functions, variables, templates by structure

Regular expressions are like the language of wizards for working with text. First it scares you, then it makes you happy! Try, play, write templates. And to practice with pleasure - look in the application Code 🐾

Code is an application for learning programming: courses in HTML, CSS, JavaScript and Python with simple explanations and practice that is really memorable.
💻 Learn for pleasure: https://itcodik.com/

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card