Chapter 7, Text Processing and Regular Expressions

  1. A regular expression is a method used in programming for pattern matching. Regular expressions provide a flexible and concise means to match strings of text.
  2. Following is the answer:
import redef is_allowed_specific_char(string):
charRe = re.compile(r'[^a-zA-Z0-9.]')
string = charRe.search(string)
return not bool(string)
print(is_allowed_specific_char("ABCDEFabcdef123450"))
print(is_allowed_specific_char("*&%@#!}{"))
  1. Answer: a.
    re is a part of the standard library and can be imported using import re.
  1. Answer: a.
    It will look for the pattern at the beginning and return None if it isn't found.
  2. Answer: d.
    This function returns the entire match.