We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Let's break down the regular expression^\S{3}\.\S{3}\.\S{3}\.\S{3}$:
^: This asserts the start of the string.
\S{3}: This matches exactly three non-whitespace characters (\S matches any non-whitespace character, and {3} specifies that exactly three of such characters should be matched).
\.: This matches a period (dot) character literally. The backslash \ is an escape character to ensure that the dot is treated as a literal character and not as a special regex character.
\S{3}: This matches exactly three non-whitespace characters again.
\.: This matches another period (dot) character literally.
\S{3}: This matches exactly three non-whitespace characters again.
\.: This matches another period (dot) character literally.
\S{3}: This matches exactly three non-whitespace characters again.
\.: This matches another period (dot) character literally.
\S{3}: This matches exactly three non-whitespace characters again.
$: This asserts the end of the string.
So, overall, this regular expression pattern matches strings that have the following structure: "XXX.XXX.XXX.XXX", where each "X" represents any non-whitespace character and there are exactly three such characters separated by periods.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matching Anything But a Newline
You are viewing a single comment's thread. Return to all comments →
Let's break down the regular expression
^\S{3}\.\S{3}\.\S{3}\.\S{3}$
:^
: This asserts the start of the string.\S{3}
: This matches exactly three non-whitespace characters (\S
matches any non-whitespace character, and{3}
specifies that exactly three of such characters should be matched).\.
: This matches a period (dot) character literally. The backslash\
is an escape character to ensure that the dot is treated as a literal character and not as a special regex character.\S{3}
: This matches exactly three non-whitespace characters again.\.
: This matches another period (dot) character literally.\S{3}
: This matches exactly three non-whitespace characters again.\.
: This matches another period (dot) character literally.\S{3}
: This matches exactly three non-whitespace characters again.\.
: This matches another period (dot) character literally.\S{3}
: This matches exactly three non-whitespace characters again.$
: This asserts the end of the string.So, overall, this regular expression pattern matches strings that have the following structure: "XXX.XXX.XXX.XXX", where each "X" represents any non-whitespace character and there are exactly three such characters separated by periods.