User:ArrowHead294/Regex snippets: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
Line 21: Line 21:
| <code><nowiki>(\d+[Ll])\s*(\d+[Ss])</nowiki></code>
| <code><nowiki>(\d+[Ll])\s*(\d+[Ss])</nowiki></code>
| <code><nowiki>$1&amp;nbsp;$2</nowiki></code>
| <code><nowiki>$1&amp;nbsp;$2</nowiki></code>
| Make sure ''x''L&nbsp;''y''s notation for MOS scales are non-wrapped
| rowspan="2" | Make sure ''x''L&nbsp;''y''s notation for MOS scales are non-wrapped
|-
| <code><nowiki>(\d+[Ll])\s*(\d+[Mm])\s*(\d+[Ss])</nowiki></code>
| <code><nowiki>$1&amp;nbsp;$2&amp;nbsp;$3</nowiki></code>
|-
|-
| <code><nowiki>(?<=(?:colspan|rowspan|id|style)="?.*?"?)\s*((?:\||!){1,3})\s*</nowiki></code>
| <code><nowiki>(?<=(?:colspan|rowspan|id|style)="?.*?"?)\s*((?:\||!){1,3})\s*</nowiki></code>

Revision as of 17:22, 22 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*([^\|\{\}\r\n]*)\s*(=+)
or (?<=\n)(\=+)\s*([^\|\{\}\r\n\]*)\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&nbsp;$2 Make sure xys notation for MOS scales are non-wrapped
(\d+[Ll])\s*(\d+[Mm])\s*(\d+[Ss]) $1&nbsp;$2&nbsp;$3
(?<=(?:colspan|rowspan|id|style)="?.*?"?)\s*((?:\||!){1,3})\s*  $1  Space out inline cell separators*
<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

See also