Displaying page
of
pages;
Items to
Title |
Test
Details
Split URL authority
|
Expression |
^(?!.*\n.*)(?:([^:]*)(?::(.*?))?@)?([^:]*)(?::([^:]*?))?$
|
Description |
For the purposes of this regex, the authority/domain of a URL comes after the scheme + "//", and includes an optional username, password, and port.
This is a perl-compatible regex (PCRE) that captures the various parts of the a domain, including the (optional) username, (optional) password, host, and (optional) port. The capturing groups are as follows: 1 = username, 2 = password, 3 = host, 4 = post. See the source link for the logic behind parsing the domain. NOTE: This is NOT intended to parse entire URLs, you will need a separate regular expression to extract the domain. Technically, only strings with newline characters are non-matches. The rest yield empty capturing groups. ANOTHER NOTE: This does NOT verify that only ascii characters are used in domain names. It is intended to extract pieces from domains that should already be valid.
|
Matches |
|
Non-Matches |
\n | : | @
|
Author |
Rating:
Not yet rated.
Tyler Durkota
|
Title |
Test
Details
Match Python/JavaScript strings
|
Expression |
([\"']).*?[^\\]\1
|
Description |
Matches strings in source code for languages that allow string to be single- or double-quoted.
|
Matches |
It's called "Montezuma's revenge" | "string with a \"string\" in it" | Two 'quotes' on a single "line"
|
Non-Matches |
Mom's cooking | " | "improperly closed string'
|
Author |
Rating:
Not yet rated.
Tyler Durkota
|
Title |
Test
Details
Extracting bible verses with Vim
|
Expression |
/(\d?\s?\w+),(\d+),(\d+),(/d*),/\1 \2:\3-\4/g
|
Description |
I had a CSV file with following format: book,chapter,verse_start,verse_end,notes
I wanted to transform the rows to traditional english verse representations (i.e. "1 Timothy 2:2-4")
Unfortunately, this regex always puts a '-' after the verse_start, so if verse_end is empty, the translated version will have a trailing '-'.
Vim needs everything escaped, so here is the actual vim command for the substitution:
:%s/\(\d\?\s\?\w\+\),\(\d\+\),\(\d\+\),\(\d*\),/\1 \2:\3-\4/g
|
Matches |
1 Timothy,2,2,4,|John,6,3,,|A,123,4,4,
|
Non-Matches |
12 Timothy,2,2,4,|2 Timothy 2,2,4|A Corinthians 3,3,,|John,3,,,|John,3,,3,
|
Author |
Rating:
Not yet rated.
Tyler Durkota
|
Displaying page
of
pages;
Items to