Sunday, July 29, 2018

Python - Using Python to Access Web Data - Regular Expression - Quiz


Question 1

1
point

1. Question 1


Which of the following best describes "Regular Expressions"?


A way to solve Algebra formulas for the unknown value


The way Python handles and recovers from errors that would otherwise cause a traceback


A way to calculate mathematical values paying attention to operator precedence


A small programming language unto itself
Question 2
1
point

2. Question 2


Which of the following is the way we match the "start of a line" in a regular expression?


^


str.startswith()


\linestart


String.startsWith()


variable[0:1]
Question 3
1
point

3. Question 3


What would the following mean in a regular expression? [a-z0-9]


Match any number of lowercase letters followed by any number of digits


Match anything but a lowercase letter or digit


Match any text that is surrounded by square braces


Match a lowercase letter or a digit


Match an entire line as long as it is lowercase letters or digits
Question 4
1
point

4. Question 4


What is the type of the return value of the re.findall() method?


A string


A list of strings


A single character


A boolean


An integer
Question 5
1
point

5. Question 5


What is the "wild card" character in a regular expression (i.e., the character that matches any character)?


^


$


+


*


.


?
Question 6
1
point

6. Question 6


What is the difference between the "+" and "*" character in regular expressions?


The "+" matches at least one character and the "*" matches zero or more characters


The "+" matches upper case characters and the "*" matches lowercase characters


The "+" matches the beginning of a line and the "*" matches the end of a line


The "+" matches the actual plus character and the "*" matches any character


The "+" indicates "start of extraction" and the "*" indicates the "end of extraction"
Question 7
1
point

7. Question 7


What does the "[0-9]+" match in a regular expression?


One or more digits


Any mathematical expression


Zero or more digits


Several digits followed by a plus sign


Any number of digits at the beginning of a line
Question 8
1
point

8. Question 8


What does the following Python sequence print out?
1
2
3
x = 'From: Using the : character'
y = re.findall('^F.+:', x)
print(y)


From:


:


['From:']


['From: Using the :']


^F.+:
Question 9
1
point

9. Question 9


What character do you add to the "+" or "*" to indicate that the match is to be done in a non-greedy manner?


?


$


\g


**


^


++
Question 10
1
point

10. Question 10


Given the following line of text:
1
From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
What would the regular expression '\S+?@\S+' match?


From


\@\


marquard@uct


stephen.marquard@uct.ac.za


d@u

3 comments: