Find All Python imports

Published on Tue Mar 01 2022

Additional matching regexes for
Find All Python imports

Email

Python

Extract parts of a URL on Python

Extract parts of a URL on Python

streets with one or more names with unicode characters in python

streets with one or more names with unicode characters in python

Indian Phone Numbers!

This is not supported in Javascript! Works well for php, python. Examples: +91-8800119719, 08800119719, 8800119719, +918800119719 etc.

Python-Dunder-Underscore

# Python Dunder Underscore Regular Expression # ## Match ## ```python # coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r'^(__version__)(\s?=\s?)+("(.*)")' test_str = "__version__ = \"0.1.1.1\"" matches = re.search(regex, test_str) if matches: print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group())) for groupNum in range(0, len(matches.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum))) # Note: for Python 2.7 compatibility, use ur'' to prefix the regex and u"" to prefix the test string and substitution. ``` ## Substitution ## ### Full String Replacement ### ```python # coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r'^(__version__)(\s?=\s?)+("(.*)")' test_str = "__version__ = \"0.1.1.1\"" subst = "[Replacement]" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 1) if result: print (result) # Note: for Python 2.7 compatibility, use ur'' to prefix the regex and u"" to prefix the test string and substitution. ``` ### Dunder Replacement ### ```python # coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r'(__version__)(\s?=\s?)+("(.*)")' test_str = "__version__ = \"0.1.1.1\"" subst = "[Dunder-Replacement] \\g<3>" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 1) if result: print (result) # Note: for Python 2.7 compatibility, use ur'' to prefix the regex and u"" to prefix the test string and substitution. ``` ### Version Replacement ### ```python # coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r'(__version__)(\s?=\s?)+("(.*)")' test_str = "__version__ = \"0.1.1.1\"" subst = " \\g<1> = [Dunder-Replacement]" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 1) if result: print (result) # Note: for Python 2.7 compatibility, use ur'' to prefix the regex and u"" to prefix the test string and substitution. ```

Triple Quoted String

More powerful than python style, this supports things like `"""" """"`, which matches totally. Also supports `"""a""""""b"""`, where there are two matches: `"""a"""`,`"""b"""`.

Complete imgur link regex

This regex grabs all kinds of imgur links and groups them in meaningful names aswell. This way you have full flow-control in your python-scripts.

printf conversion specification parsing

Parses `printf` conversion specifications. This version detects multiple flags and ` `(space) flag. MSVC length modifier `I64` is also supported. I'm using this regex in my Python project, so please change accordingly if you use other flavor of regex.

camelCase2snake_case

Convert camelCase to snake_case. In `Python` the `\L` case modifier in the substitution pattern to lower case is not supported. ```py def camelCase2snake_case(txt): """ Convert camelCase to snake_case https://regex101.com/r/D3a0de/2/ """ txt = re.sub(r'([A-Z]+)', '_\\1', txt.strip()) txt = txt.lower() return txt ``` [JV-conseil](https://github.com/JV-conseil)

Distinguish torrent files (series vs movies)

A neat regex for finding out whether a given torrent name is a series or a movie. Returns the full name of the series with the separator needed to make it pretty (ie, replace it with space or what you want). Also returns the season number or the year for the movie/series, depending on what was previously matches. If I had done this in perl there would be much less logic needed in the regex, but python is what I'm working with so..