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 18: Line 18:
| <code><nowiki>$1&nbsp;</nowiki></code>
| <code><nowiki>$1&nbsp;</nowiki></code>
| Space out pipe characters and header separators in tables (one cell per line)*
| Space out pipe characters and header separators in tables (one cell per line)*
|-
| <code><nowiki>(?<=\n)(\||!)[^\S\r\n]*\|?[^\S\r\n]*(?!-|\})</nowiki></code>
| <code><nowiki>$1&nbsp;</nowiki></code>
| Replace <code>!&nbsp;{{pipe}}&nbsp;</code> and <code>{{pipe}}&nbsp;{{pipe}}&nbsp;</code> with <code>!&nbsp;</code> and <code>{{pipe}}&nbsp;</code>, respectively
|-
|-
| <code><nowiki>(?<=\[\[|\|)(\d+[Ll])\s*(\d+[Ss])(?=\]\]])?(?!\s)</nowiki></code>
| <code><nowiki>(?<=\[\[|\|)(\d+[Ll])\s*(\d+[Ss])(?=\]\]])?(?!\s)</nowiki></code>
Line 31: Line 35:
| 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-length lookaheads and lookbehinds
<nowiki />* Requires support for variable-width lookaheads and lookbehinds


== See also ==
== See also ==

Revision as of 18:38, 14 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\t]+)\s*(=+)(?=\n*) $1 $2 $3 Space out equals signs for section headers*
(?<=\n)\|\s*(?!-|\{|\}) $1  Space out pipe characters and header separators in tables (one cell per line)*
(?<=\n)(\||!)[^\S\r\n]*\|?[^\S\r\n]*(?!-|\}) $1  Replace ! |  and | |  with and , respectively
(?<=\[\[|\|)(\d+[Ll])\s*(\d+[Ss])(?=\]\]])?(?!\s) $1 $2 Make sure xys notation for MOS scales are non-wrapped
(?<!(?:<(\w+-)*\w+>[^\n]*(?=<\/(\w+-)*\w+>)|\{|\}))[^\S\r\n]*(\|\|\|?|!!!?)[^\S\r\n]*(?!-|[^\n]*<\/(\w+-)*\w+>(?=<(\w+-)*\w+>)|\{|\})  $1  Space out pipe characters and header separators in tables (entire row per line)*
<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