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 1: Line 1:
These are some regular expressions I use for formatting purposes:
<noinclude>These are some regular expressions I use for formatting purposes:
 
</noinclude>
{| class="wikitable" style="text-align: center;"
{| class="wikitable" style="text-align: center;"
|+ style="font-size: 105%;" | [[User:ArrowHead294|ArrowHead294]]'s regular expressions for formatting Wiki markup
|-
|-
! Pattern
! Pattern
Line 44: Line 45:
| Standalone fractions with single-digit numerators and denominators can be done using {{tlx|frac}} or {{tlx|sfrac}} and don't need to be TeXified
| Standalone fractions with single-digit numerators and denominators can be done using {{tlx|frac}} or {{tlx|sfrac}} and don't need to be TeXified
|}
|}
<nowiki />* Requires support for variable-width lookaheads and lookbehinds
<nowiki />* Requires support for variable-width lookaheads and lookbehinds<noinclude>


== See also ==
== See also ==
Line 50: Line 51:


[[Category:Regular expressions]]
[[Category:Regular expressions]]
</noinclude>

Revision as of 17:21, 25 January 2025

These are some regular expressions I use for formatting purposes:

ArrowHead294's regular expressions for formatting Wiki markup
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*(=+)(?=\n)
or (?<=\n)(\=+)\s*([^\|\{\}\r\n\=]*)\s*(\=+)(?=\n)
$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
(?<=\{\|.*?\n)(?<!\|-\n)(\||!) |-\n$1 Insert table cell separator at top of table before first headers
(\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|scope|style)="?.*?"?)[^\S\r\n]*(?<![Ff]ile.*?)((?:\||!){1,3})[^\S\r\n]*  $1  Space out inline cell separators*
(?<!\n|\{)[^\S\r\n]*(?<![Ff]ile.*?)((?:\||!){1,3})[^\S\r\n]*
(?<=\n)((?:\*|:)+)\s* $1  Space out
<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