User:ArrowHead294/Regex snippets: Difference between revisions
Jump to navigation
Jump to search
ArrowHead294 (talk | contribs) mNo edit summary |
ArrowHead294 (talk | contribs) mNo edit summary |
||
Line 3: | Line 3: | ||
{| class="wikitable" style="text-align: center;" | {| class="wikitable" style="text-align: center;" | ||
|- | |- | ||
! | ! Pattern | ||
! | ! Replace by | ||
! | ! Purpose | ||
|- | |- | ||
| <code><nowiki>^(?:\+|-|\x{2212})?(?:(?:\d{1,3}?(?:\,\d{3})*|\d+)\.?\d*|\d*\.?\d+)(?:[Ee][+-]?\d+)?$</nowiki></code> | | <code><nowiki>^(?:\+|-|\x{2212})?(?:(?:\d{1,3}?(?:\,\d{3})*|\d+)\.?\d*|\d*\.?\d+)(?:[Ee][+-]?\d+)?$</nowiki></code> |
Revision as of 17:06, 21 January 2025
These are some regular expressions I use for formatting purposes:
Pattern | Replace by | Purpose |
---|---|---|
^(?:\+|-|\x{2212})?(?:(?:\d{1,3}?(?:\,\d{3})*|\d+)\.?\d*|\d*\.?\d+)(?:[Ee][+-]?\d+)?$
|
N/A | Match a number |
(?<=\n)(=+)\s*((?:[^\s=]+\s*)+[^\s=])\s*(=+) or (?<=\n)(\=+)\s*((?:[^\s\=]+\s*)+[^\s\=])\s*(\=+)
|
$1 $2 $3
|
Space out equals signs for section headers* |
(?<=\n)(\||!)[^\S\r\n]*\|?[^\S\r\n]*(?!-|\}|\+)
|
$1
|
Space out pipe characters and header separators in tables (one cell per line) and replace ! | and | | with ! and | , respectively
|
(\d+[Ll])\s*(\d+[Ss])
|
$1 $2
|
Make sure xL ys notation for MOS scales are non-wrapped |
<math>,*\s*\\frac(\d)(\d),*\s*<\/math>
|
{{frac|$1|$2}} or{{sfrac|$1|$2}}
|
Standalone fractions with single-digit numerators and denominators can be done using {{frac}} or {{sfrac}} and don't need to be TeXified
|
* Requires support for variable-width lookaheads and lookbehinds