Regex Flags
Flags are used to modify the behavior of a regex pattern. Flags are also known as modifiers. They determine whether the pattern is case-sensitive, multi-line, etc.
Global Flag
The global
flag /g
is used to search for all occurrences of a pattern in a string.
For example, the regex pattern /go/g
matches all occurrences of go
in a string.
Case-Insensitive Flag
The case-insensitive
flag /i
is used to perform a case-insensitive search.
For example, the regex pattern /go/i
matches go
, Go
, and GO
.
Multi-Line Flag
The multi-line
flag /m
is used to perform a multi-line search.
For example, the regex pattern /^go/m
matches go
at the start of each line.