1 23-Regex


Previous: 22-DataVis.html

23-Regex/regular_expressions.png

1.1 Screencasts

1.2 Wildcards and globbing

https://en.wikipedia.org/wiki/Wildcard_character
https://en.wikipedia.org/wiki/Glob_(programming)
* In software, a wildcard character is a kind of placeholder represented by a single character, such as an asterisk (), which can be interpreted as a number of literal characters or an empty string.
It is often used in file searches so the full name need not be typed.

List all python files in the current directory:
ls *.py

List files that have any character in the 4th position:
ls wha?.py

Some common ones include:
| symbol | match |
|:——-|:—————————————————————————–|
| * | matches any number of any characters including no characters |
| ? | matches any single character |
| [abc] | matches one character given in the bracket |
| [a-z] | matches one character from the (locale-dependent) range given in the bracket |

1.2.1 glob

https://docs.python.org/3/library/glob.html
import glob # for pathnames only, not general strings

1.3 Regular expressions (Regex)

A regular expression (shortened as regex or regexp, also referred to as rational expression) is a sequence of characters that define a search pattern. Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation.
* https://en.wikipedia.org/wiki/Regular_expression
* https://docs.python.org/3/howto/regex.html
* https://docs.python.org/3/library/re.html
* https://www.debuggex.com/cheatsheet/regex/python (show)
* http://v4.software-carpentry.org/regexp/index.html
* https://stackoverflow.com/questions/452104/is-it-worth-using-pythons-re-compile

1.3.1 Code

23-Regex/re.py

Regular expressions are sometimes jokingly referred to as “write-only”, a ploy on filesystem permissions like read-only.

1.4 Conclusions

Some people, when confronted with a problem, think:
“I know, I’ll use regular expressions.”
Now they have two problems.
23-Regex/regex.png

+++++++++++++++ Cahoot-23.1
https://mst.instructure.com/courses/58101/quizzes/57595

Next: 24-EvilEval.html