Path: csiph.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!2.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!news.mb-net.net!open-news-network.org!.POSTED.178.197.212.81!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Help with regexp Date: Tue, 10 Aug 2021 13:45:04 +0200 Organization: PointedEars Software (PES) Lines: 50 Message-ID: <21167627.EfDdHjke4D@PointedEars.de> References: <3136550.aeNJFYEL58@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.212.81"; logging-data="3578"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.10 Cancel-Lock: sha1:JKkyePCcnD/PH7E1sj+ytxurXHo= X-User-ID: U2FsdGVkX19ZaaE58k9CvyT2cDMy+Ae4sT8X6fP7bXu0+iKWTVcCCg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. On 8/08/2021 5:56 am, Thomas 'PointedEars' Lahn wrote: >> const generateHex2Rgba = >> ((alpha = 1) => ((hex, red, green, blue, count) => { >> let [r, g, b] = [red, green, blue].map(s => parseInt(s, 16)); >> return `rgba(${r},${g},${b},${alpha})`; >> })); > > Nice and concise code Thank you. > but what is 'count' for? It should have better been named “offset”, and apparently is only an artifact of code from my memory of more general code that I had written before. The formal parameter that follows the formal parameters for the captures (here: “red”, “green”, and “blue”) would be assigned the offset of the match, and the formal parameter that followed that would be assigned the original string value: [Do you also yearn for the days when the ECMAScript Language Specification was written in formal language, yes, and it wasn’t clickable, but at least it was not completely shrouded in abstractions? I for one cannot see anymore how that describes the (actual) behavior of the “replace” method in this case. Where is the check for RegExp? Or are we supposed to use “replaceAll” now? (Should I just have brunch first instead?)] I must have misremembered that it this formal parameter would need to be specified in order for the capture parameters be assigned the correct value, as I cannot produce by testing, or find in documentation, supporting evidence now. Specifically the following historical example indicates that there is no backwards compatibility issue, and that it can be safely omitted in this case: -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.