Module talk:String

Extract number
I am trying to extract a number from a string and ignore any units. I have been using first word which works in some cases.


 * 45 -> 45
 * 18.6 -> 18.6

In the second case it doesn't work. I think because a nbsp is being used instead of a space. Is there any template which will work for both? &mdash; Martin (MSGJ · talk) 08:20, 11 April 2022 (UTC)
 * You can use Special:ExpandTemplates to see that convert outputs  for the second case above. What is the purpose of this? If it's for convert and if you can control the parameters, using abbr=values would make selection easier. For the second case above, that would give  . Johnuniq (talk) 11:01, 11 April 2022 (UTC)
 * It's for importing data into Wikidata from infobox fields. I can't control the parameters because convert is used separately on each article. &mdash; Martin (MSGJ · talk) 19:36, 11 April 2022 (UTC)

Template:Str rep pattern match irregularities
Editors interested in this module may be interested in the following discussion: Template talk:Str rep. Your feedback would be welcome. Mathglot (talk) 08:14, 8 October 2022 (UTC)

How to do string.replace of level3 headers in transcluded wikitext
I am trying to use replace to strip out the level3 headers from a transclusion of Dublin North-West (Dáil constituency).

However  leaves the level3 headers in place -- see my /sandbox test page at special:permalink/1164910747

Any suggestions? Feel free to edit that sandbox if it helps. Brown HairedGirl (talk) • (contribs) 21:13, 11 July 2023 (UTC)


 * I have never seen the #section-h construction before. Would you mind explaining where that comes from? &mdash; Martin (MSGJ · talk) 21:50, 11 July 2023 (UTC)
 * See Help:Labeled section transclusion. * Pppery * it has begun... 22:09, 11 July 2023 (UTC)
 * Turns out this has nothing to do with Lua: when using an equals sign in an argument to a template or module you need to name the parameter explicitly or escape it with :  should work. * Pppery * it has begun...  22:09, 11 July 2023 (UTC)
 * Bless you @Pppery. That's done it.  Thanks also to @Trappist the monk  for appplyig the fix to my sandbox -- I am not sure which of you did what first, but you have both been a great help, and mighty promptly.
 * I case you are curious, this is for my development of the Constituency Teachtaí Dála navbox meta-template. When I used it to make Kerry (Dáil constituency)/TDs, the level3 headers were an annoying intrusion, but now I can make 'em vanish from the navbox. Thanks again.   Brown HairedGirl  (talk) • (contribs) 22:35, 11 July 2023 (UTC)
 * This isn't quite what you were asking, but related enough you might be interested in it: Conditional heading. Mathglot (talk) 04:50, 12 July 2023 (UTC)
 * Thanks, @Mathglot. I want to remove the headings rather than to promote or demote them, so it's not what I need in this case. But it's good to know about this, for future refrence.   Brown HairedGirl  (talk) • (contribs) 23:11, 12 July 2023 (UTC)

Protected edit request on 21 September 2023
On Latin Wikipedia I have created a tiny module named Module:Translitteratio, which contains a single function named. The function accepts three parameters and works exactly like the  M4 macro (but with the order of arguments changed to chars, replacement, string). For example,

generates


 * Lrëm ìpsm dlr sìt ämët, cnsëctëtr ädìpìscìng ëlìt. Näm mllìs, mëts äc vltpät äctr, sëm lìglä ìntërdm nllä, äc pëllëntësqë nìbh ërät sëd nìsì. Intëgër nëc äctr rcì. Qìsqë nìbh mëts, vìvërrä ët vìvërrä nëc, lärëët ìn mì. Intëgër älìqët, märìs vìtäë trìstìqë frìngìllä, äntë dì ltrìcës qäm, ët fërmëntm rcì prs nëc lrëm. Intëgër qìs vëhìclä ärc, ët lärëët ënìm. Nllä ëìsmd nëqë vëlìt, ëgët ìäclìs mässä tëmpr t. Nllä cnvällìs mäxìms nëqë ët prttìtr. In nnc ërs, cnvällìs ìd psërë äc, ëgëstäs ët ärc. Aënëän fäcìbs sllìcìtdìn ìpsm, ìn cndìmëntm märìs mäxìms ìn. Etìäm fäcìlìsìs ërs vël trtr tìncìdnt ìäclìs. Vëstìblm lrëm lëcts, psërë sëd ënìm ìn, värìs phärëträ lrëm. Mrbì nìsl läcs, ëlëìfënd t rnä vìtäë, ìntërdm cnsëqät ìpsm. Cräs t ìmpërdìët äntë. Sëd qìs lcts prs, qìs prtä ërät. Ut grävìdä grävìdä ägë ä ëìsmd.

(You can experiment with it in the Latin Wikipedia sandbox page)

This allowed to write the template, which transforms vowels with various accents into simple vowels, and the  template, which writes fractions using only Unicode characters (no HTML).

I think that Module:String would benefit from this function, with its name changed from  to.

Translated into English, the code to add to this module would be:

Grufo (talk) 17:40, 21 September 2023 (UTC)
 * This feels sufficiently obscure that it doesn't belong in this module, unless some actual use case can be presented here unrelated to what other wikis do. * Pppery * it has begun... 22:02, 21 September 2023 (UTC)
 * What is obscure, what it does or its code? What it does is well explained by the documentation of M4's  (this is just a clone). As for what can be done with it, I believe template  has no languages. --Grufo (talk) 01:28, 22 September 2023 (UTC)
 * Yes, and why should we care? Why is the Unicode system for fractions superior to the one currently in use? Why should we invent more ways to do the same thing? * Pppery * it has begun... 01:33, 22 September 2023 (UTC)
 * I believe this discussion started with the wrong foot. This is a generic function proposal, it is not a proposal about the template. In fact, the other template that uses this proposal  does something completely different (i.e. removing accents from vowels). I have no problem answering questions about, but I would kindly ask you to stay on topic on this function proposal. Re: Why should we invent more ways to do the same thing? Because there are many cases where you have no alternatives. For instance, you can write,
 * ↳ 100 carats
 * but you cannot use the CSS/HTML solution used by Fraction inside Abbr. But again, since it is a generic function proposal, frankly I think it will find most of its applications in the transliteration of alphabets rather than in fractions (that was indeed only one example). It is such a basic functionality that it has been part of Unix since the old days. For instance, if you look at the code of you will find
 * All that does is mapping each digit to its superscript unicode character. If we wanted to do the same using we would need ten module invocations. --Grufo (talk) 01:55, 22 September 2023 (UTC)
 * We already have Module:MultiReplace for that. Yes, the syntax you used is slightly terser than that module's syntax, but there's no need to shake up the world. * Pppery * it has begun... 02:09, 22 September 2023 (UTC)
 * I have not done a speed test, but I suspect that syntax will not be the only thing where this function will greatly beat Module:MultiReplace. In fact, I suspect that performance will be tremendously less expensive here. This function is less powerful (the mapping happens verbatim character by character), hence, exactly for this reason, it is possible to map without problems strings that are page-long – while I suspect that Module:MultiReplace will break the servers in that case. If all this seems unrealistic, think about the amount of Unicode characters: just to map four types of accents in I had to write the following string:
 * I assure you, there can be way more complex transliterations than this. And last but not least: in terms of both computational complexity and ease of use, what you call “shaking up the world” is rather a going back to the old days. --Grufo (talk) 02:26, 22 September 2023 (UTC)
 * Yes, and do we really care? Don't make speculative claims about breaking the servers - see WP:PERF. I'm still not convinced that we need any of this level of complexity instead of just letting people type what they want to type rather than relying on templates to fix it for them and it's clear we won't convince each other at this point. * Pppery * it has begun... 02:33, 22 September 2023 (UTC)
 * Fine. Continuing with this spirit interface-wise Latin Wikipedia will soon beat English Wikipedia. --Grufo (talk) 02:41, 22 September 2023 (UTC)
 * I assure you, there can be way more complex transliterations than this. And last but not least: in terms of both computational complexity and ease of use, what you call “shaking up the world” is rather a going back to the old days. --Grufo (talk) 02:26, 22 September 2023 (UTC)
 * Yes, and do we really care? Don't make speculative claims about breaking the servers - see WP:PERF. I'm still not convinced that we need any of this level of complexity instead of just letting people type what they want to type rather than relying on templates to fix it for them and it's clear we won't convince each other at this point. * Pppery * it has begun... 02:33, 22 September 2023 (UTC)
 * Fine. Continuing with this spirit interface-wise Latin Wikipedia will soon beat English Wikipedia. --Grufo (talk) 02:41, 22 September 2023 (UTC)

Protected edit request on 25 October 2023
Please, add r to the word fist (resulting in first), line number 61. Nishimoto, Gilberto Kiyoshi (talk) 18:11, 25 October 2023 (UTC)