7 pat t e r n m at c h I n g w I t h r e g u L a r e X p r e s s I o n s



Yüklə 397,03 Kb.
Pdf görüntüsü
səhifə25/25
tarix29.11.2022
ölçüsü397,03 Kb.
#71308
1   ...   17   18   19   20   21   22   23   24   25
P A T T E R N M A T C H I N G W I T H

Practice Projects
For practice, write programs to do the following tasks.
Date Detection
Write a regular expression that can detect dates in the DD/MM/YYYY for-
mat. Assume that the days range from 01 to 31, the months range from 01 
to 12, and the years range from 1000 to 2999. Note that if the day or month 
is a single digit, it’ll have a leading zero.
The regular expression doesn’t have to detect correct days for each 
month or for leap years; it will accept nonexistent dates like 31/02/2020 or 
31/04/2021. Then store these strings into variables named 
month

day
, and 
year
, and write additional code that can detect if it is a valid date. April, 
June, September, and November have 30 days, February has 28 days, and 
the rest of the months have 31 days. February has 29 days in leap years. 
Leap years are every year evenly divisible by 4, except for years evenly divis-
ible by 100, unless the year is also evenly divisible by 400. Note how this cal-
culation makes it impossible to make a reasonably sized regular expression 
that can detect a valid date.
Strong Password Detection
Write a function that uses regular expressions to make sure the password 
string it is passed is strong. A strong password is defined as one that is at 
least eight characters long, contains both uppercase and lowercase charac-
ters, and has at least one digit. You may need to test the string against mul-
tiple regex patterns to validate its strength.
Regex Version of the strip() Method
Write a function that takes a string and does the same thing as the 
strip()
string method. If no other arguments are passed other than the string to 
strip, then whitespace characters will be removed from the beginning and 
end of the string. Otherwise, the characters specified in the second argu-
ment to the function will be removed from the string.

Yüklə 397,03 Kb.

Dostları ilə paylaş:
1   ...   17   18   19   20   21   22   23   24   25




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin