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


Groups > comp.lang.javascript > #21138

Re: Recommendation for new RegExp (Array-extra-like) methods

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.fsmpi.rwth-aachen.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <1458401.hGLh0OfnHy@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Sun, 01 Sep 2013 15:25:24 +0200
User-Agent KNode/4.10.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Recommendation for new RegExp (Array-extra-like) methods
Newsgroups comp.lang.javascript
References <ac07e89f-90ee-4b6d-a524-5adfadd0cb94@googlegroups.com> <3573991.qt74eh6WeI@PointedEars.de>
MIME-Version 1.0
Lines 49
NNTP-Posting-Date 01 Sep 2013 15:25:26 CEST
NNTP-Posting-Host b7f5d4c0.newsspool3.arcor-online.net
X-Trace DXC=<HBZjmHQIVPFm0Y?OE@2^XMcF=Q^Z^V3X4Fo<]lROoRQ8kF<OcfhCO[jWdeJAGglJQDZm8W4\YJN\b@mF9jNikdUDZIgZChmYc[1W;XSEBTY_U
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:21138

Show key headers only | View raw


Thomas 'PointedEars' Lahn wrote:

> You might instead find my jsx.regexp.RegExp useful, which among other
> features allows you to name subpatterns and access by that name the
> corresponding matches:
> 
>   /* ?<Perl> style; also supports ?'Perl' style and ?P<ython> style */
>   var regex = new jsx.regexp.RegExp("^(?<first>.+?): (?<second>.+)$",
>   "mg"),
>       str = "key1: val1\nkey2: key2",
>       match;
> 
>   while ((match = regex.exec(str)))
>   {
>     console.log(match.groups["first"], match.groups["second"]);
>     console.log(match[1], match[2]);
>   }
> 
> “regex” holds an augmented RegExp instance then, whose inherited exec()
> method has been overridden in the instance to return an augmented
> array-like object if necessary (otherwise just the inherited method is
> called, and its return value returned):
> 
>       /**
>        * @function
>        */
>       exec: (function () {
>         var rx2;
> 
>         /**
>          * @param {string} s
>          * @param {jsx.regexp.RegExp} rx
>          *   Instance to be tested
>          * @return {boolean}
                     ^^^^^^^^^
>          *   <code>true</code> if <var>rx</var> has been constructed
>          *   using this constructor, <code>false</code> otherwise.

JFTR: As you can see further below, this is a documentation bug that will be 
fixed in the next revision.  The return value of the custom method is 
exactly what the original RegExp.prototype.exec() method would have had 
returned (“null” or a reference to an Array-like object), augmented with 
custom properties if there is a match.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


Thread

Recommendation for new RegExp (Array-extra-like) methods brettz9@gmail.com - 2013-08-28 07:51 -0700
  Re: Recommendation for new RegExp (Array-extra-like) methods Andreas Bergmaier <andber93@web.de> - 2013-08-28 17:16 +0200
    Re: Recommendation for new RegExp (Array-extra-like) methods brettz9@gmail.com - 2013-08-28 08:21 -0700
      Recommendation for array-like methods on Iterator; Was Re: Recommendation for new RegExp (Array-extra-like) methods brettz9@gmail.com - 2013-08-28 16:30 -0700
  Re: Recommendation for new RegExp (Array-extra-like) methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-30 16:00 +0200
    Re: Recommendation for new RegExp (Array-extra-like) methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-01 15:25 +0200

csiph-web