@@ -226,36 +226,42 @@ False
226226
227227### <a name =" regular-expressions " ></a >Regular Expressions
228228
229- * Handy reference of regular expression elements
229+ * Handy reference of regular expression (RE) elements
230230
231231| Meta characters | Description |
232232| ------------- | ----------- |
233- | ` ^ ` | anchor, match from beginning of string |
234- | ` $ ` | anchor, match end of string |
233+ | ` \A ` | anchors matching to beginning of string |
234+ | ` \Z ` | anchors matching to end of string |
235+ | ` ^ ` | anchors matching to beginning of line |
236+ | ` $ ` | anchors matching to end of line |
235237| ` . ` | Match any character except newline character ` \n ` |
236238| | ; | OR operator for matching multiple patterns |
237- | ` () ` | for grouping patterns and also extraction |
239+ | ` (RE) ` | capturing group |
240+ | ` (?:RE) ` | non-capturing group |
238241| ` [] ` | Character class - match one character among many |
239- | ` \^ ` | prefix ` \ ` to match meta characters like ` ^ ` |
242+ | ` \^ ` | prefix ` \ ` to literally match meta characters like ` ^ ` |
240243
241244<br >
242245
243- | Quantifiers | Description |
246+ | Greedy Quantifiers | Description |
244247| ------------- | ----------- |
245- | ` * ` | Match zero or more times the preceding character |
246- | ` + ` | Match one or more times the preceding character |
247- | ` ? ` | Match zero or one times the preceding character |
248+ | ` * ` | Match zero or more times |
249+ | ` + ` | Match one or more times |
250+ | ` ? ` | Match zero or one times |
251+ | ` {m,n} ` | Match ` m ` to ` n ` times (inclusive) |
252+ | ` {m,} ` | Match at least m times |
253+ | ` {,n} ` | Match up to ` n ` times (including ` 0 ` times) |
248254| ` {n} ` | Match exactly n times |
249- | ` {n,} ` | Match at least n times |
250- | ` {n,m} ` | Match at least n times but not more than m times |
255+
256+ Appending a ` ? ` to greedy quantifiers makes them non-greedy
251257
252258<br >
253259
254260| Character classes | Description |
255261| ------------- | ----------- |
256262| ` [aeiou] ` | Match any vowel |
257263| ` [^aeiou] ` | ` ^ ` inverts selection, so this matches any consonant |
258- | ` [a-f] ` | Match any of abcdef character |
264+ | ` [a-f] ` | ` - ` defines a range, so this matches any of abcdef characters |
259265| ` \d ` | Match a digit, same as ` [0-9] ` |
260266| ` \D ` | Match non-digit, same as ` [^0-9] ` or ` [^\d] ` |
261267| ` \w ` | Match alphanumeric and underscore character, same as ` [a-zA-Z0-9_] ` |
@@ -267,21 +273,22 @@ False
267273
268274<br >
269275
270- | Compilation Flags | Description |
276+ | Flags | Description |
271277| ------------- | ----------- |
272- | ` re.I ` | ignore case |
273- | ` re.M ` | multiline mode, ` ^ ` and ` $ ` anchors work on internal lines |
274- | ` re.S ` | singleline mode, ` . ` will also match ` \n ` |
275- | ` re.V ` | verbose mode, for better readability and adding comments |
278+ | ` re.I ` | Ignore case |
279+ | ` re.M ` | Multiline mode, ` ^ ` and ` $ ` anchors work on lines |
280+ | ` re.S ` | Singleline mode, ` . ` will also match ` \n ` |
281+ | ` re.V ` | Verbose mode, for better readability and adding comments |
276282
277- * [ Python docs - Compilation Flags] ( https://docs.python.org/3/howto/regex.html#compilation-flags ) - for more details and long names for flags
283+ See [ Python docs - Compilation Flags] ( https://docs.python.org/3/howto/regex.html#compilation-flags ) for more details and long names for flags
278284
279285<br >
280286
281287| Variable | Description |
282288| ------------- | ----------- |
283- | ` \1 ` , ` \2 ` , ` \3 ` etc | backreferencing matched patterns |
284- | ` \g<1> ` , ` \g<2> ` , ` \g<3> ` etc | backreferencing matched patterns, useful to differentiate numbers and backreferencing |
289+ | ` \1 ` , ` \2 ` , ` \3 ` ... ` \99 ` | backreferencing matched patterns |
290+ | ` \g<1> ` , ` \g<2> ` , ` \g<3> ` ... | backreferencing matched patterns, prevents ambiguity |
291+ | ` \g<0> ` | entire matched portion |
285292
286293<br >
287294
@@ -471,14 +478,16 @@ True
471478
472479### <a name =" further-reading-on-regular-expressions " ></a >Further Reading on Regular Expressions
473480
481+ * [ Python re(gex)?] ( https://github.com/learnbyexample/py_regular_expressions ) - a book on regular expressions
474482* [ Python docs - re module] ( https://docs.python.org/3/library/re.html )
475483* [ Python docs - introductory tutorial to using regular expressions] ( https://docs.python.org/3/howto/regex.html )
476- * [ developers.google - Regular Expressions tutorial] ( https://developers.google.com/edu/python/regular-expressions )
477- * [ automatetheboringstuff - Regular Expressions] ( https://automatetheboringstuff.com/chapter7/ )
478484* [ Comprehensive reference: What does this regex mean?] ( https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean )
485+ * [ rexegg] ( https://www.rexegg.com/ ) - tutorials, tricks and more
486+ * [ regular-expressions] ( https://www.regular-expressions.info/ ) - tutorials and tools
487+ * [ CommonRegex] ( https://github.com/madisonmay/CommonRegex ) - collection of common regular expressions
479488* Practice tools
480- * [ online regex tester ] ( https://regex101.com/#python ) shows explanations, has reference guides and ability to save and share regex
481- * [ regexone] ( http ://regexone.com/) - interative tutorial
489+ * [ regex101 ] ( https://regex101.com/ ) - visual aid and online testing tool for regular expressions, select flavor as Python before use
490+ * [ regexone] ( https ://regexone.com/) - interative tutorial
482491 * [cheatsheet](https://www.shortcutfoo.com/app/dojos/python-regex/cheatsheet) - one can also learn it [interactively](https://www.shortcutfoo.com/app/dojos/python-regex)
483492 * [regexcrossword](https://regexcrossword.com/) - practice by solving crosswords, read 'How to play' section before you start
484493
0 commit comments