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 18: | Line 18: | ||
| <code><nowiki>(?<=\n)(\||!)[^\S\r\n]*\|?[^\S\r\n]*(?!-|\}|\+)</nowiki></code> | | <code><nowiki>(?<=\n)(\||!)[^\S\r\n]*\|?[^\S\r\n]*(?!-|\}|\+)</nowiki></code> | ||
| <code><nowiki>$1 </nowiki></code> | | <code><nowiki>$1 </nowiki></code> | ||
| Space out pipe characters and header separators in tables (one cell per line)<br />Replace <code>! {{pipe}} </code> and <code>{{pipe}} {{pipe}} </code> with | | Space out pipe characters and header separators<br />in tables (one cell per line)<br />Replace <code>! {{pipe}} </code> with <code>! </code> and <code>{{pipe}} {{pipe}} </code> with <code>{{pipe}} </code> | ||
|- | |- | ||
| <code><nowiki>(?<=\{\|.*?\n)(?<!\|-\n)(\||!)</nowiki></code> | | <code><nowiki>(?<=\{\|.*?\n)(?<!\|-\n)(\||!)</nowiki></code> | ||
| <code><nowiki>|-\n$1</nowiki></code> | | <code><nowiki>|-\n$1</nowiki></code> | ||
| Insert table cell separator at top of table before first headers | | Insert table cell separator at top of table before<br />first headers | ||
|- | |- | ||
| <code><nowiki>(\d+[Ll])\s*(\d+[Ss])</nowiki></code> | | <code><nowiki>(\d+[Ll])\s*(\d+[Ss])</nowiki></code> | ||
| <code><nowiki>$1&nbsp;$2</nowiki></code> | | <code><nowiki>$1&nbsp;$2</nowiki></code> | ||
| rowspan="2" | Make sure ''x''L ''y''s | | rowspan="2" | Make sure ''x''L ''y''s is non-wrapped | ||
|- | |- | ||
| <code><nowiki>(\d+[Ll])\s*(\d+[Mm])\s*(\d+[Ss])</nowiki></code> | | <code><nowiki>(\d+[Ll])\s*(\d+[Mm])\s*(\d+[Ss])</nowiki></code> | ||
| Line 35: | Line 35: | ||
| rowspan="2" | Space out inline cell separators* | | rowspan="2" | Space out inline cell separators* | ||
|- | |- | ||
| <code><nowiki>(?<!\n|\{)[^\S\r\n]*(?<![Ff] | | <code><nowiki>(?<!\n|\{)[^\S\r\n]*(?<!\[\[:?[Ff][Ii][Ll][Ee]:.*?)((?:\||!){1,3})[^\S\r\n]*</nowiki></code> | ||
|- | |- | ||
| <code><nowiki>(?<=\n)((?:\*|:)+)\s*</nowiki></code> | | <code><nowiki>(?<=\n)((?:\*|:)+)\s*</nowiki></code> | ||
| Line 43: | Line 43: | ||
| <code><nowiki><math>,*\s*\\frac(\d)(\d),*\s*<\/math></nowiki></code> | | <code><nowiki><math>,*\s*\\frac(\d)(\d),*\s*<\/math></nowiki></code> | ||
| <code><nowiki>{{frac|$1|$2}}</nowiki></code> or<br /><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 | | Standalone fractions with single-digit numerators<br />and denominators don't need to be TeXified | ||
|} | |} | ||
<nowiki />* Requires support for variable-width lookaheads and lookbehinds<noinclude> | <nowiki />* Requires support for variable-width lookaheads and lookbehinds<noinclude> | ||
Revision as of 14:01, 28 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*(=+)(?=\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) Replace ! | with ! and | | with |
|
(?<=\{\|.*?\n)(?<!\|-\n)(\||!)
|
|-\n$1
|
Insert table cell separator at top of table before first headers |
(\d+[Ll])\s*(\d+[Ss])
|
$1 $2
|
Make sure xL ys is non-wrapped |
(\d+[Ll])\s*(\d+[Mm])\s*(\d+[Ss])
|
$1 $2 $3
| |
(?<=(?:class|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][Ii][Ll][Ee]:.*?)((?:\||!){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 don't need to be TeXified |
* Requires support for variable-width lookaheads and lookbehinds