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.
Well, I don't see a '.' (period) character in sinithwar's regex, but it normally is a "wildcard", which can match any one single character. For example, the pattern "ca." would match words like can, cap, car, cat, and so forth. However when inside a character class, it acts like a literal period. The '-' (hyphen) character is the other way around, being literal and boring on its own, but has a special meaning inside character classes. It lets you specify a bunch of characters very quickly. So, "[0-9a-f]" is the same as "[0123456789abcdef]". You could read it aloud as "everything from 0 to 9, inclusive, and also from a to f, inclusive". Hope that summary makes enough sense!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Valid Username Regular Expression
You are viewing a single comment's thread. Return to all comments →
Well, I don't see a
'.'
(period) character in sinithwar's regex, but it normally is a "wildcard", which can match any one single character. For example, the pattern"ca."
would match words like can, cap, car, cat, and so forth. However when inside a character class, it acts like a literal period. The'-'
(hyphen) character is the other way around, being literal and boring on its own, but has a special meaning inside character classes. It lets you specify a bunch of characters very quickly. So,"[0-9a-f]"
is the same as"[0123456789abcdef]"
. You could read it aloud as "everything from 0 to 9, inclusive, and also from a to f, inclusive". Hope that summary makes enough sense!