Replace text and regular expressions: Difference between revisions
Jump to navigation
Jump to search
Ttenbergen (talk | contribs) Created page with "Confuses me every time, so hoping to leave example this time. Special:ReplaceText allows use of regular expressions, see [https://www.mediawiki.org/wiki/Extension:Replac..." |
Ttenbergen (talk | contribs) m Text replacement - "[[Category: " to "[[Category:" |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
[[Special:ReplaceText]] allows use of regular expressions, see [https://www.mediawiki.org/wiki/Extension:Replace_Text#Using_regular_expressions their documentation]. | [[Special:ReplaceText]] allows use of regular expressions, see [https://www.mediawiki.org/wiki/Extension:Replace_Text#Using_regular_expressions their documentation]. | ||
Example | ===Simple Example=== | ||
*Page has <code>abcdefghi</code> | *Page has <code>abcdefghi</code> | ||
** Original text: <code>abcdef(.*)hi</code> ''ie want it to match the "g"'' | ** Original text: <code>abcdef(.*)hi</code> ''ie want it to match the "g"'' | ||
| Line 9: | Line 9: | ||
*results in <code>wxgyz</code> | *results in <code>wxgyz</code> | ||
[[Category: Wiki | === Example with line end anchor === | ||
Not sure why it had to be used, but without it the rest of the words didn't get matched. | |||
* Before text (title): (T) Wrist Joint | |||
* O: \(T\) (.*)$ ''the $ shows end of line'' | |||
* R: $1 (T) | |||
* After text: Wrist Joint (T) | |||
== Example to match variations with inconsistent capitalization (and I think inconsistent spacing) == | |||
Two other cents, to find any and all variations. (assuming one template parameter per line) | |||
Search: "(?i)(\n) *\| *tItEl *=.*\n" | |||
Replace: "$1" | |||
== Related articles == | |||
{{Related Articles}} | |||
[[Category:Wiki use]] | |||
Latest revision as of 11:05, 30 July 2025
Confuses me every time, so hoping to leave example this time.
Special:ReplaceText allows use of regular expressions, see their documentation.
Simple Example
- Page has
abcdefghi- Original text:
abcdef(.*)hiie want it to match the "g" - Replacement text:
wx$1yzie want it to put the matched string between wx and yz
- Original text:
- results in
wxgyz
Example with line end anchor
Not sure why it had to be used, but without it the rest of the words didn't get matched.
- Before text (title): (T) Wrist Joint
- O: \(T\) (.*)$ the $ shows end of line
- R: $1 (T)
- After text: Wrist Joint (T)
Example to match variations with inconsistent capitalization (and I think inconsistent spacing)
Two other cents, to find any and all variations. (assuming one template parameter per line) Search: "(?i)(\n) *\| *tItEl *=.*\n" Replace: "$1"
Related articles
| Related articles: |