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 60: | Line 60: | ||
| <code><nowiki>| $1 = $2</nowiki></code> | | <code><nowiki>| $1 = $2</nowiki></code> | ||
| Change to new comment format when migrating from<br /><code>{{<nowiki />Scale tree}}</code> to <code>{{<nowiki />MOS tuning spectrum}}</code> | | Change to new comment format when migrating from<br /><code>{{<nowiki />Scale tree}}</code> to <code>{{<nowiki />MOS tuning spectrum}}</code> | ||
|- | |||
| <code><nowiki>\{(?:.|\n)*?([Zz][Pp][Ii])(?:.|\n)*?\|\s*(?:\[\[)?(\d+).*?\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*.*?\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*.*</nowiki></code> | |||
| <code><nowiki>{{$1\n| zpi = $2\n| steps = $3\n| step size = $3\n| tempered height = $4\n\n| integral = $5\n| gap = $6\n| octave = $7\n| consistent = $8\n| distinct = $9\n}}</nowiki></code> | |||
| Changing ZPI tables to template form | |||
|} | |} | ||
<nowiki />* Requires support for variable-width lookaheads and lookbehinds<noinclude> | <nowiki />* Requires support for variable-width lookaheads and lookbehinds<noinclude> |
Revision as of 14:57, 20 March 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)?)(?:\|\+\s*\n)?(\||!)(?!-|\}|\+)
|
|-\n$1
|
Add in |- before first row after caption (not strictlynecessary, but including it is good practice) |
(?<=(?:\||!).*?)(?<!-)\n+(?!\||!)
|
<br />
|
Replace linebreaks in cells with <br />
|
(\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]*((?:\||!){1,3})[^\S\r\n]*(.*?)(?=\n)
|
$1="$2" $3 $4
|
Space out inline cell separators* |
(?<!\n|\{)[^\S\r\n]*(?<!\[\[:?\w+:.*?)((?:\||!){1,3})[^\S\r\n]*(.*?)(?=\n)
|
$1
| |
(?<=(?:\{\{|\[\[).*?)\s+(\|)\s+
|
|
| |
(\d+)(?:\s*[Tt][Oo]\s*|-)(\d+)\s*[Cc](?:ent[s]?)?
|
$1–$2{{c}}
|
|
(?<=\n)((?:\*|:)+)\s*
|
$1
|
Space out asterisks, number signs, and colons for lists |
<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 |
(.*?)\s*:\s*(.*?);
|
| $1 = $2
|
Change to new comment format when migrating from{{Scale tree}} to {{MOS tuning spectrum}}
|
\{(?:.|\n)*?([Zz][Pp][Ii])(?:.|\n)*?\|\s*(?:\[\[)?(\d+).*?\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*.*?\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*(.*?)\n\|\s*.*
|
{{$1\n| zpi = $2\n| steps = $3\n| step size = $3\n| tempered height = $4\n\n| integral = $5\n| gap = $6\n| octave = $7\n| consistent = $8\n| distinct = $9\n}}
|
Changing ZPI tables to template form |
* Requires support for variable-width lookaheads and lookbehinds