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 20: | Line 20: | ||
|- | |- | ||
| <code><nowiki><math>,*\s*\\frac(\d)(\d),*\s*<\/math></nowiki></code> | | <code><nowiki><math>,*\s*\\frac(\d)(\d),*\s*<\/math></nowiki></code> | ||
| <code><nowiki>{{sfrac|$1|$2}}</nowiki></code> | | <code><nowiki>{{frac|$1|$2}}</nowiki></code> or<br /><code><nowiki>{{sfrac|$1|$2}}</nowiki></code> | ||
| Standalone fractions with single-digit numerators and denominators can be done using | | 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-length lookaheads and lookbehinds |
Revision as of 15:28, 4 December 2024
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 |
(?<!(<\/\w+>[^\n]*)|\{|\})(?<=\n)(\||!)\s*(?!-|<\/\w+>|\{|\})
|
$1
|
Space out pipe characters and header separators in tables (one cell per line)* |
(?<!(?:<\/\w+>[^\n]*(?=<\/\w+>)|\{|\}))[^\S\r\n]*(\|\|\|?|!!!?)[^\S\r\n]*(?!-|[^\n]*<\/\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-length lookaheads and lookbehinds