You can modify a regular expression pattern with options
that affect matching behavior.
For this purpose regular expressions can have various modifiers.
Modifiers that relate to the interpretation of the regular expression
are listed below.
i
Specifies case-insensitive matching.
s
Specifies single-line mode.
Changes the meaning of the period character ( . )
to match any character whatsoever, even a newline, which normally it would not match.
m
Specifies multiline mode.
Changes the meaning of ^ and $ so that they match at the beginning
and end, respectively, of any line,
not just the beginning and end of the whole string.
g
Specifies global replace mode.
Indicates that a search should find and replace all occurrences of the pattern
within the searched string, not just the first one.
x
Extend your pattern's legibility by permitting whitespace and comments.
/^\s*$/
/\b\w+\b/
/\b(\w+)\s+\1\b/i
Match a repeated word in any case.
/\d\d-\d\d-\d\d\d\d/
Match a date with format dd-mm-yyyy.
/(\d{1,2})\/(\d{1,2})\/(\d{4}|\d{2})/$2-$1-$3/
Change date format from dd/mm/yyyy to mm-dd-yyyy.
/\b(\w+)\b/($1)/g
Enclose any word with brackets.
/^\s*(.*?)\s*$/$1/s
Remove leading and trailing spaces from a string.
/^\s*(.*?)\s*$/$1/mg
Remove leading and trailing spaces from each line in a string.