Which regular expression will locate all valid usernames?

Last Updated on August 1, 2021 by Admin 2

You have been asked to collect all the usernames from an access log. According to policy, usernames must be at least six characters and no more than sixteen characters. Usernames can only include lowercase letters, numbers, underscores, and hyphens, such as the following:

200-201 Part 05 Q06 012
200-201 Part 05 Q06 012

Which regular expression will locate all valid usernames?

  • 200-201 Part 05 Q06 013
    200-201 Part 05 Q06 013
  • 200-201 Part 05 Q06 014
    200-201 Part 05 Q06 014
  • 200-201 Part 05 Q06 015
    200-201 Part 05 Q06 015
  • 200-201 Part 05 Q06 016
    200-201 Part 05 Q06 016
Explanation:
The regular expression Щ[a-z0-9_-]{6,16}$ will locate all valid usernames. The Щ and $ indicate the beginning and end of the pattern, respectively. The characters inside of the square brackets [] specify what is allowable, being a lowercase letter (a-z), number (0-9), underscore (_), or hyphen (-). The values in the curly braces {} specifies the minimum number of occurrences, being at least six, but no more than sixteen characters.

The regular expression Щ[az0_16]?$ only finds usernames with a single characters a, z, 0, 1, _, or 6. Also, the question mark (?) will match these characters zero or one time, returning empty matches.

The regular expression Щ[a-z1-6]+$ will locate only usernames that contain one or more lowercase letters or the digits 1 through 6. The plus sign (+) will match one or more occurrence.

The regular expression Щ[az0_16]*$ will locate only usernames that contain the characters 1, z, 0, _, 1 or 6. Also, the asterisk (*) will match zero or more occurrences, returning empty matches.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments