Common/hard-to-write regular expressions
Find lines that are at the end of paragraphs that don't have periods at the end.
^[^\n][^(\.\n)]+[^\.]\n\r?\n\r?
Example:
This is a paragraph and it
has newline characters inside
it.You want to detect lines that
don't have trailing periods,
but you don't want to detect
the lines without periods
that are in the middle of a
paragraphWell, this is the regex for
you!
Find v4 UUIDs.
[a-f0-9-]{36}
([a-f0-9]{4}-?){8}
[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}
[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}
[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}
Example
ee-eeeeee-eeeeeeeeee-eeeeeeeeeeeeee- #1
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee #1
------------------------------------ #1
eeee-eeee-eeee-eeee-eeee-eeee-eeee-eeee- #2
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee #2
eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee #3
eeeeeeee-eeee-4eee-eeee-eeeeeeeeeeee #4
eeeeeeee-eeee-4eee-9eee-eeeeeeeeeeee #5
Find newlines. Does not catch \n\n
or \r\r
as one new line.
\r
- Mac\n
- Linux\r\n
- Windows(\r\n|\n|\r)
- Windows, Mac, and Linux
Catch tabs that are not being used as indentation.
[^\t\n\r]\t
Catch missing semicolons in languages that require them. Assumes newline = \r\n
, and one or fewer statements per line.
Allows lines without semicolons to end with ,
, {
, }
, &
, and >
. Catches other lines.
^[^;\r\n]+[^\[;,\{\}&>]\r\n
Not very good around full/multi-line comments, but that's what humans are for.
Find titles in markdown strings.
(?:^\#(.+)|(.+)(?:\r\n|\r|\n)(---+|===+)$)