1 Write a Regular Expression that will match a date that follows the following s
ID: 3714920 • Letter: 1
Question
1 Write a Regular Expression that will match a date that follows the following standard “DD-MM-YYYY”
2 Write a Rregular Expression matching a decimal with a precision of 4.
3 What does the following Regular Expression match?
/[a-zA-Z][a-zA-Z]*/
True
False
4 Write a Regular Expression that will match a traditional SSN.
5 What does the following Regular Expression match?
/^CST-3523$/
6 What is use of Regular Expressions?
7 What the following Regular Expression matches?
/Fox>/
8 What is Regular Expressions?
9 What the following Regular Expression matches?
/^[^0-9]$/
Explanation / Answer
1.
d{1,2}-d{1,2}-d{4}
d{1,2} - matches 1 or 2 digits
- - matches -
d{4} - matches 4 digits
22-2-2018 - valid
02-02-1992 - valid
2-3-1923 - valid
12-3-122 - invalid
123-03-1243 - invalid
2.
d*.d{4}
d* - matches one or more number of digits
. - matches .
d{4} - matches 4 digits
0.3242 - valid
1213.2222 - valid
1233.22 - invalid
11.111 - invalid
.2222 - valid
4.4444 - valid
3.
[a-zA-Z][a-zA-Z]*
[a-zA-Z] - matches any character in set a-z and A-Z
[a-zA-Z]* - matches any character in set a-z and A-Z , * means 0 or more number of times
acBBBBB - valid
a - valid
Zaa - valid
Z - valid
4.
SSN is a 9 digit number in format AAA-BB-CCCC
d{3}-d{2}-d{4}
111-22-3333 - valid
aa1-33-2222 - invalid
1-11-1111 - invalid
111-1-1111 - invalid
111-11-111 - invalid
111-11-1111 - valid
999-99-9999 - valid
5.
^CST-3523$ - matches literally this CST-3523 nothing else
6.
Regular expression are used in searching , pattern matching , parsing in computer programming.
For example -
In some program, regular expression can be made to validate SSN, phone number, URl, email Id etc.
7.
/Fox>/ - matches Fox> in a string
8.
Regular expression is a pattern consisting of letters, special symbols, digits etc.
which is to be searched from a string or a phrase.
9.
^[^0-9]$ - matches a character other than list 0-9
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.