Regular Expressions
Regular expressions (also "regex" or "regexp") are a powerful way to look for patterns in text, and we employ regular expressions in the PyReconstruct interface mainly to filter lists. To filter a list, you will be asked for an expression you would like to evaluate for. You will therefore need to understand a little bit about how regular expressions are constructed. Here, we present the bare minimum to get up and running.
After browsing this page you might want to learn more, and YouTube has a wealth of information about using regular expressions in Python. Simply search for "regular expression python". Be aware that many programming languages have their own, unique spin on regular expressions. Regular expressions in Emacs and elisp, for example, differ from those in Python, so be sure you are looking specifically into Python regular expressions. You can write very complicated regular expressions in Python to match a variety of patterns, and for a definitive, in-depth discussion, please see the Python documentation on the re module.
Basic characters
Expression | Explainer | Examples | Matches |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sets
Sets are collections of characters enclosed in square brackets.
Expression | Explainer | Examples | Matches |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quantifiers
Quantifiers modify the element immediately to its left and allow you to specify how many times a pattern should be matched. Combining sets with quantifiers becomes a powerful way to filter lists in PyReconstruct.
Expression | Explainer | Examples | Matches |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Special characters
You might actually want to match a special character literally. For example, a period in Python regular expressions is interpreted as "any character", but you might need to match a period in the name of an object. To do this, place a backslash before the character.
Expression | Explainer | Examples | Matches |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|