-
Use the regex library by typing
import re
-
A regex pattern looks like this:
r"<pattern>" r"(\d{4}(\-?)){4}"
-
re.match()
vsre.search()
?re.match()
only checks from the beginningre.search()
checks anywhere in the string- Example:
>>> re.match("c", "abcdef") # No match >>> re.search("c", "abcdef") # Match
- https://docs.python.org/3/library/re.html#search-vs-match
-
re.match()
returns the first occurrence, whilere.findall()
returns all the matches -
re.sub(A, B, target_string)
replaces A with B in target_string
Last active
October 23, 2019 05:35
-
-
Save yi-mei-wang/3073646c271797c1eecf63589b560d00 to your computer and use it in GitHub Desktop.
Regular expressions in Python
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment