Table Purgatory

Published on Tue Mar 01 2022

A regex to find all nowrap text occurrences and name all the groups involved in preparation for a replacement pass

Additional matching regexes for
Table Purgatory

Table Purgatory

A regex to find all nowrap text occurrences and name all the groups involved in preparation for a replacement pass

nginx log parser

separate nginx log into database table-style fields

sql: insert into

insert into table ( a, b, c ) values ( " insert into values (1,2,3)",1,2.3,"a,b" ); insert into table (ee,bb,cc) values (aa,234,"asj",2.3);

Timecode

Regex to match standard timecode format. (Updated with fewer groups).

GHS - PF LIMIT EXTRACTOR

Extracts from a PF file the summary table from the RAH command

Replace second grouping with first

Identifies two groups, each group using a regex, then replaces group 2 with group 1.

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. ```

Fetch data between curly braces with plain text

This regex fetch only the data between content in curly braces (first occurrence, use preg_match_all in php, for all occurrences). This is useful for bad JSON files with wrong format or text between.

Simple TIN number regex

- Only accept numerics/digits and hyphens, forbidding them at the start and the end of the number, and avoid two consecutive occurrences.

Extract URL parts only named capturing groups

Extract URL parts only named capturing groups