Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #40340

Re: Help with regexp

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Help with regexp
Date 2021-08-10 13:45 +0200
Organization PointedEars Software (PES)
Message-ID <21167627.EfDdHjke4D@PointedEars.de> (permalink)
References <lZadnd6QivChfpH8nZ2dnUU7-L3NnZ2d@westnet.com.au> <3136550.aeNJFYEL58@PointedEars.de> <F9SdnRF4Svb6AI38nZ2dnUU7-TPNnZ2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> 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:

<https://262.ecma-international.org/#sec-string.prototype.replace>

  [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:

<http://web.archive.org/web/20040929130418/http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/string.html#1194258>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Help with regexp Andrew Poulos <ap_prog@hotmail.com> - 2021-08-06 17:22 +1000
  Re: Help with regexp Andrew Poulos <ap_prog@hotmail.com> - 2021-08-06 17:41 +1000
    Re: Help with regexp Andrew Poulos <ap_prog@hotmail.com> - 2021-08-06 17:55 +1000
      Re: Help with regexp Julio Di Egidio <julio@diegidio.name> - 2021-08-06 01:39 -0700
        Re: Help with regexp Julio Di Egidio <julio@diegidio.name> - 2021-08-06 01:53 -0700
        Re: Help with regexp Andrew Poulos <ap_prog@hotmail.com> - 2021-08-07 09:19 +1000
          Re: Help with regexp Julio Di Egidio <julio@diegidio.name> - 2021-08-06 17:26 -0700
      Re: Help with regexp Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-08-06 10:36 +0000
        Re: Help with regexp Andrew Poulos <ap_prog@hotmail.com> - 2021-08-07 09:17 +1000
          Re: Help with regexp Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-08-07 18:57 +0000
  Re: Help with regexp The Natural Philosopher <tnp@invalid.invalid> - 2021-08-06 19:10 +0100
  Re: Help with regexp Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-08-07 21:56 +0200
    Re: Help with regexp Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-08-07 22:02 +0200
    Re: Help with regexp Andrew Poulos <ap_prog@hotmail.com> - 2021-08-09 13:13 +1000
      Re: Help with regexp Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-08-10 13:45 +0200
        Re: Help with regexp Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-08-10 12:28 +0000
          Re: Help with regexp Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-08-11 16:03 +0200

csiph-web