aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorSergey M <dstftw@gmail.com>2019-01-01 23:13:39 +0700
committerGitHub <noreply@github.com>2019-01-01 23:13:39 +0700
commit696f4e41149a8f91e963d33e2f6ea9bc835f2260 (patch)
tree7069e0bccefb40415182425f1be8cdfa450bb6e4 /README.md
parent0e713dbb116493181218c38dc03716feda2fa7d9 (diff)
[README.md] Add more guide lines for regular expressions
Diffstat (limited to 'README.md')
-rw-r--r--README.md28
1 files changed, 25 insertions, 3 deletions
diff --git a/README.md b/README.md
index b3c39bf66..bdc5faeec 100644
--- a/README.md
+++ b/README.md
@@ -1133,11 +1133,33 @@ title = meta.get('title') or self._og_search_title(webpage)
This code will try to extract from `meta` first and if it fails it will try extracting `og:title` from a `webpage`.
-### Make regular expressions flexible
+### Regular expressions
-When using regular expressions try to write them fuzzy and flexible.
+#### Don't capture groups you don't use
+
+Capturing group must be an indication that it's used somewhere in the code. Any group that is not used must be non capturing.
+
+##### Example
+
+Don't capture id attribute name here since you can't use it for anything anyway.
+
+Correct:
+
+```python
+r'(?:id|ID)=(?P<id>\d+)'
+```
+
+Incorrect:
+```python
+r'(id|ID)=(?P<id>\d+)'
+```
+
+
+#### Make regular expressions relaxed and flexible
+
+When using regular expressions try to write them fuzzy, relaxed and flexible, skipping insignificant parts that are more likely to change, allowing both single and double quotes for quoted values and so on.
-#### Example
+##### Example
Say you need to extract `title` from the following HTML code: