Skip to content

Chapter 5: Regular Expressions #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chrisoemma opened this issue May 17, 2020 · 1 comment
Open

Chapter 5: Regular Expressions #7

chrisoemma opened this issue May 17, 2020 · 1 comment
Assignees
Labels
class notes New class notes or request

Comments

@chrisoemma
Copy link
Collaborator

chrisoemma commented May 17, 2020

Regular expression or regex - we use them but don't love them! 😬 😆

According to Wikipedia, regular expressions are:

A sequence of characters that define a search pattern.

If Wikipedia is not enough you, check out grep.

Everyone knows grep. Its reputation precedes it. Maybe the most of us don't care for how it works, but we love it because, it just works.

With that said, the following is a deep-dive into Regular Expressions using Python. The aim of this issue is for us to better understand how grep works. Enjoy!

--

Discussion Points

  • Case Study: Street Addresses
  • Case Study: Roman Numerals
  • Using the {n,m} Syntax
  • Case Study: Parsing Phone Numbers
@chrisoemma chrisoemma added the class notes New class notes or request label May 17, 2020
@joshuamabina
Copy link
Contributor

joshuamabina commented May 19, 2020

A few questions to help our understanding of regular expressions as used in Python.

  1. The most obvious regex application would be searching. What applications come to mind when you think of regex? (Hint: search for a piece of text, then [do something]).

  2. The author speaks fondly of string helper functions i.e. find(), urging us to use them instead of regex, whenever possible.

    a. Why does the author urge the use of string functions over regex?

    b. When would it be considered proper to use regex of string functions?

  3. For good measure and for the fun of it, using a language of your choice, can you employ regular expressions to Match Anything But A New Line? View challenge on HackerRank.

  4. Write a regex that will match a string S using the condition, S should begin with py followed by 1 or 4 digits.

  5. ______ makes a pattern optional.

  6. ______ matches the end of a string.

  7. ______ matches the start of a string.

  8. \b matches the ______ of a string.

  9. \B matches the ______ of a string.

  10. | in a regex indicates ______.

  11. ______ in a regex indicates grouping.

  12. \d matches ______ of a string.

  13. \D matches ______ of a string.

  14. x+ matches ______ of a string.

  15. x* matches ______ of a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
class notes New class notes or request
Projects
None yet
Development

No branches or pull requests

2 participants