LaTeX Clean Up with Regex
- New line at the end of each sentence
([^.][a-z][.][ ])Exclude first period to exclude abbreviations, any letter period space at the end of line$1\nAdd new line after match
- New line after ;
([^.][a-z][;][ ])$1\n
- New line after ?
([^.][a-z][?][ ])$1\n
- New line after
.([^.][a-z][\.]["][ ])- ``
- Remove multiple spaces between words in a sentence.
- New line at the end of each paragraph
- Change beginning double quote
"to open quote ```` - Change ending double quote " to close quote ''
---to \textemdash...to \textellipsis- Space after abbreviations
Dr.\ , Mr.\ , Mrs.\ , Ms.\ , Fig.\ , St.\ , U.S.A.\ , U. S.\ , U.S.S.R.\ , vs.\, Inc.\, N.\Y.\ - Fix World War II ---
ll ii li il 11 - Escape $ in currencies,
\$100 million - Sentences ending with a capital letter should end with an end-of-sentence space--
\@, exWorld War I\@. There were... - En dash expected for range of numbers,
1990--94 - Abbreviation should be followed by a normal space,
the G.I.\ soldiers - Reference without a non-breaking space,
~\ref - Missing a space after a comma but before a number
,\d+
Webstorm
Summary of regular-expression constructs
Characters
| Construct | Matches |
|---|---|
| x | The character x |
| \ | The backslash character |
| \0n | The character with octal value 0n (0 <= n <= 7) |
| \0nn | The character with octal value 0nn (0 <=n<= 7) |
| \0mnn | The character with octal value 0mnn (0 <= m <= 3, 0 <= n <= 7) |
| \xhh | The character with hexadecimal value 0xhh |
| \uhhhh | The character with hexadecimal value 0xhhhh |
| \t | The tab character ('\u0009') |
| \n | The newline (line feed) character ('\u000A') |
| \r | The carriage-return character ('\u000D') |
| \f | The form-feed character ('\u000C') |
| \a | The alert (bell) character ('\u0007') |
| \e | The escape character ('\u001B') |
| \cx | The control character corresponding to x |
Character classes
| Construct | Matches |
|---|---|
| abc | a, b, or c (simple class) |
| [^abc] | Any character except a, b, or c (negation) |
| a-zA-Z | a through z or A through Z, inclusive (range) |
| a-dm-p | a through d, or m through p: a-dm-p (union) |
| a-z&&def | d, e, or f (intersection) |
| a-z&&[^bc] | a through z, except for b and c: ad-z (subtraction) |
| a-z&&[^m-p] | a through z, and not m through p: a-lq-z (subtraction) |
Predefined character classes
| Construct | Matches |
|---|---|
| . | Any character (may or may not match line terminators) |
| \d | A digit: 0-9 |
| \D | A non-digit: [^0-9] |
| \s | A whitespace character: \t\n\x0B\f\r |
| \S | A non-whitespace character: [^\s] |
| \w | A word character: a-zA-Z_0-9 |
| \W | A non-word character: [^\w] |
POSIX character classes (US-ASCII only)
| Construct | Matches |
|---|---|
| \p | A lower-case alphabetic character: a-z |
| \p | An upper-case alphabetic character:A-Z |
| \p | All ASCII:\x00-\x7F |
| \p | An alphabetic character:\p\p |
| \p | A decimal digit: 0-9 |
| \p | An alphanumeric character:\p\p |
| \p | Punctuation: One of !"#$%&'()*+,-./:;=>?@]^_`~ | |
| \p | A visible character: \p\p |
| \p | A printable character: \p\x20 |
| \p | A space or a tab: \t |
| \p | A control character: \x00-\x1F\x7F |
| \p | A hexadecimal digit: 0-9a-fA-F |
| \p | A whitespace character: \t\n\x0B\f\r |
java.lang.Character classes (simple java character type)
| Construct | Matches |
|---|---|
| \p | Equivalent to java.lang.Character.isLowerCase() |
| \p | Equivalent to java.lang.Character.isUpperCase() |
| \p | Equivalent to java.lang.Character.isWhitespace() |
| \p | Equivalent to java.lang.Character.isMirrored() |
Classes for Unicode blocks and categories
| Construct | Matches |
|---|---|
| \p | A character in the Greekblock (simple block) |
| \p | An uppercase letter (simple category) |
| \p | A currency symbol |
| \P | Any character except one in the Greek block (negation) |
| \p&&[^\p] | Any letter except an uppercase letter (subtraction) |
Boundary matchers
| Construct | Matches |
|---|---|
| ^ | The beginning of a line |
| $ | The end of a line |
| \b | A word boundary |
| \B | A non-word boundary |
| \A | The beginning of the input |
| \G | The end of the previous match |
| \Z | The end of the input but for the final terminator, if any |
| \z | The end of the input |
Greedy quantifiers
| Construct | Matches |
|---|---|
| X? | X, once or not at all |
| X* | X, zero or more times |
| X+ | X, one or more times |
| X | X, exactly n times |
| X | X, at least n times |
| X | X, at least n but not more than m times |
Reluctant quantifiers
| Construct | Matches |
|---|---|
| X?? | X, once or not at all |
| X*? | X, zero or more times |
| X+? | X, one or more times |
| X? | X, exactly n times |
| X? | X, at least n times |
| X? | X, at least n but not more than m times |
Possessive quantifiers
| Construct | Matches |
|---|---|
| X?+ | X, once or not at all |
| X*+ | X, zero or more times |
| X++ | X, one or more times |
| X+ | X, exactly n times |
| X+ | X, at least n times |
| X+ | X, at least n but not more than m times |
Logical operators
| Construct | Matches |
|---|---|
| XY | X followed by Y |
| X| Y | Either X or Y |
| (X) | X, as a capturing group |
Back references
| Construct | Matches |
|---|---|
| \n | Whatever the nth capturing group matched |
Quotation
| Construct | Matches |
|---|---|
| \ | Nothing, but quotes the following character |
| \Q | Nothing, but quotes all characters until \E |
| \E | Nothing, but ends quoting started by \Q |
Special constructs (non-capturing)
| Construct | Matches |
|---|---|
| (?:X) | X, as a non-capturing group |
| (?idmsux-idmsux) | Nothing, but turns match flags on - off |
| (?idmsux-idmsux:X) | X, as a non-capturing group with the given flags on - off |
| (?=X) | X, via zero-width positive lookahead |
| (?!X) | X, via zero-width negative lookahead |
| (?<=X) | X, via zero-width positive lookbehind |
| (?<!X) | X, via zero-width negative lookbehind |
| (?>X) | X, as an independent, non-capturing group |
More on Regular Expressions: