In linguistics, an isogram refers to a word where each letter occurs only once.
Breaking down the regular expression /(\w).*\1/i
into its components:
(\w)
: Identifies any alphanumeric character (or underscore) and saves it as the first group.
.*
: Matches any number of characters, excluding newlines.
\1
: References the first group for comparison.
The inclusion of /i
in the regex makes it case-insensitive. Essentially, this regex checks if a single letter repeats within the word.
Using regex.test(str)
asks if a string matches the regex pattern. Adding !
before it negates the result, leading to a return value that signifies an isogram – no repeated letters.