1.8 KiB
1.8 KiB
Regular expressions
TODO: ADD MORE
- the
re.sub()function of theremodule that replaces aregular expressionmatch with a new value. The example solutions use this function in various places to substitute markdown syntax for HTML syntax in the passed in markdown text. markdown - Both the original code to be refactored for this exercise and the example solution import and use the
remodule for Regular Expressions in python. markdown - the
re.match()function from theremodule returns amatchobject with any matched values from a specified Regular Expression or pre-compiled Regular Expression. The example usesre.match()in multiple places to search for text patterns that need re-formatting or substituting. markdown - Various functions in the re module return a
re.Matchinstance which in turn has aMatch.groupmethod.Match.groupexists even if there are no groups specified in the pattern. See the Match.group docs for more detail. markdown - regular expressions is a language of sorts that can detect substrings and extract groups from a string, as well as replace them with something else phone-number
- A Domain Specific Language (DSL) for text processing. Like many other programming languages in use, python supports a quasi-dialect of PCRE (Perl compatible regular expressions).
Regular expressionscan be used via the core pythonremodule, or the third-partyregexmodule. Both the original code to be refactored for this exercise and the example solutions use the coreremodule to accessregular expressionsfunctionality. markdown