Advertisement
/ /
Advertisement

Frequently Asked Questions

What is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It can be used to check if a string contains a specific pattern, to find all occurrences of a pattern, or to replace matched substrings. Regex is supported natively in JavaScript, Python, Java, PHP, and most other programming languages.

What do the flags g, i, m, and s mean?

The g (global) flag finds all matches rather than stopping at the first. The i (case-insensitive) flag makes matching ignore upper/lower case differences. The m (multiline) flag makes ^ and $ match the start and end of each line rather than the whole string. The s (dotAll) flag makes the dot (.) also match newline characters, which it normally skips.

Why does the match count change when I toggle the global flag?

Without the g flag, a regex only finds the very first match in the string, so the count is always 0 or 1. With the g flag enabled, the engine scans the entire string and reports every non-overlapping match, giving you a full count. Always enable g when you want to find all occurrences.