please Answer the following regular expressions questions(also do number 9) Q4 C
ID: 3736444 • Letter: P
Question
please Answer the following regular expressions questions(also do number 9)
Q4 Choose the pattern that finds all filenames in which the first letters of the filename are astA, followed by a
digit, followed by the file extension .txt.
1) astA[[:digit:]].txt
2) astA[[0-9]].txt
3) astA..txt
4) astA[[:digit:]].txt
Q5 What's the difference between [0-z]+ and w+ ?
1) The first one accepts 0 and z and the other doesn't.
2) The first one doesn't allow for uppercase letters.
3) The first one accepts more punctuation characters than the second one.
4) Nothing. They're identical.
Q6 What does the regular expression (d{1,2}/d{1,2}/d{4} most likely represent?
1) An American ZIP code
2) A date
3) A phone number
4) A price
Q7 What does the regular expression [a-zA-Z0-9_]{3,14} most likely represent?
1) An e-mail address
2) A street address
3) A username
4) A set of X and Y coordinates
Q8 What does the regular expression ^((0?[1-9]|1[012])(:[0-5]d){0,2}( [AP]M))$|^([01]d|2[0-3])(:[0-5]d){0,2}$
most likely represent?
1) A street address
2) A name
3) A time
4) A date
Q9 The regular expression ^d{5}-d{4}|d{5}|[A-Z]d[A-Z] d[A-Z]d$ is designed to validate American ZIP Codes
and Canadian Postal Codes but there are two problems with it. What is one of the flaws?
1) It doesn't allow for leaving the space out after the third character in the Canadian Postal Code.
2) American ZIP codes that start with 0 aren't accepted.
3) It requires that the string contain an American ZIP Code followed by a Canadian Postal Code.
4) It allows for American ZIP codes with 9 digits.
Q10 What does the regular expression ^([0-3]|[0-9][0-9]|4[0-5][0-9]|46[0-6])$ most likely represent?
1) A range of numeric values from 0 to 499.
2) A range of numeric values from 399 to 499.
3) A range of numeric values from 399 to 466
4) A range of numeric values from 0 to 466.
Explanation / Answer
Please find my answer in details.
Please find the answer below
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Q4 Choose the pattern that finds all filenames in which the first letters of the filename are astA, followed by a
digit, followed by the file extension .txt.
1) astA[[:digit:]].txt
2) astA[[0-9]].txt
3) astA..txt
4) astA[[:digit:]].txt
The answer of the above question is 2) astA[[0-9]].txt
In regular expressions, to specify the number between 0 to 9, we use the expression [0-9].
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Q5 What's the difference between [0-z]+ and w+ ?
1) The first one accepts 0 and z and the other doesn't.
2) The first one doesn't allow for uppercase letters.
3) The first one accepts more punctuation characters than the second one.
4) Nothing. They're identical.
The answer of the above question is 3) The first one accepts more punctuation characters than the second one.
w stands for "word character", usually [A-Za-z0-9_]
where as n the case of [0-Z], this is equivalent to the following more readable character class [0-9:;<=>?@A-Z]
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Q6 What does the regular expression (d{1,2}/d{1,2}/d{4} most likely represent?
1) An American ZIP code
2) A date
3) A phone number
4) A price
The answer of the above question is 2) A date
The d{1,2} specifies that it can either be 1 or 2, the next set d{1,2} also signifies 1 or 2.
The next d{4} asks the user to enter the year which is not more than 9999.
Hence it is used for date.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Q7 What does the regular expression [a-zA-Z0-9_]{3,14} most likely represent?
1) An e-mail address
2) A street address
3) A username
4) A set of X and Y coordinates
The answer of the above question is 3) A username
Since the letters can be a combinaiton of a-z A-Z or 0-9. {3,14} Gives the range where the min value is 3 and max value is 14.
so it can possibly be username, where it can be of minimum val 3 and maximum value 14.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Q8 What does the regular expression ^((0?[1-9]|1[012])(:[0-5]d){0,2}( [AP]M))$|^([01]d|2[0-3])(:[0-5]d){0,2}$
most likely represent?
1) A street address
2) A name
3) A time
4) A date
The answer of the above question is 3) A time
This part of the reg exp (0?[1-9]|1[012]) gives the hours the next part gives the mins :[0-5]d){0,2}.
This part [AP]M) is used to define whether it is AM or PM.
This part ([01]d|2[0-3])(:[0-5]d){0,2}$ is being used to get the seconds and milliseconds.
Hence, this is the regular expression for a Time
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Q10 What does the regular expression ^([0-3]|[0-9][0-9]|4[0-5][0-9]|46[0-6])$ most likely represent?
1) A range of numeric values from 0 to 499.
2) A range of numeric values from 399 to 499.
3) A range of numeric values from 399 to 466
4) A range of numeric values from 0 to 466.
The answer of the above question is 4) A range of numeric values from 0 to 466.
[0-3] gives a digit from 0-3
[0-9][0-9] gives 2 digits from 0-9 each
4[0-5][0-9] gives 3 digit, 1st digit is 4 always, 2nd can be form 0-5, 3rd digit can be from 0-9
46[0-6] gives 3 digits, where first 2 digits are 46 always, 3rd digit can be 0-6.
Hence, the minimum value is 0 and maximum value is 466.
Please upvote my answer if it helped you!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.