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


Groups > comp.lang.javascript > #18896

Re: RegExp problem

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <3460713.alAdkCt8v1@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Thu, 14 Mar 2013 21:11:47 +0100
User-Agent KNode/4.8.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: RegExp problem
Newsgroups comp.lang.javascript
References <9608f578-525d-4670-9792-0700df15eb41@googlegroups.com> <khsfbf$udt$1@dont-email.me> <XnsA183976552747eejj99@194.109.133.133> <khsmkn$m11$1@news.albasani.net> <1514068.yciYkkSlex@PointedEars.de>
MIME-Version 1.0
Lines 65
NNTP-Posting-Date 14 Mar 2013 21:11:49 CET
NNTP-Posting-Host b5d10fd5.newsspool2.arcor-online.net
X-Trace DXC=nNDoG`j;CQG=8m7nZkdN^@A9EHlD;3YcB4Fo<]lROoRA8kF<OcfhCOKL5NU2=\P19JDZm8W4\YJNLb@mF9jNikdEIQbgJMhLo0Gl9f:_6QUbnH
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:18896

Show key headers only | View raw


Thomas 'PointedEars' Lahn wrote:

> Stefan Weiss wrote:
>> On 2013-03-14 14:52, Evertjan. wrote:
>>> or my personal favorite for "any character":
>>> 
>>> [\s\S]*
>> 
>> Shortest way to match "any character including \n":
>> [^]
> 
> My research showed that this is a syntax error in Microsoft JScript in
> version 5.8.23141 (IE/MSHTML 8.0) and before (and probably in version
> 9.0.16440 in Browser Compatibility Mode, the same as with trailing commas
> in Object and Array initialisers), and in Opera ECMAScript in version 9.64
> and before.  [\s\S] is the safe approach.

However, it should be noted that JSX:regexp.js [1, 2] supports PCRE_DOTALL 
since revision 275 (2012-09-19 CE) with

  var rx = new jsx.regexp.RegExp(/./, "s");

or 

  var rx = new jsx.regexp.RegExp(".", "s");

being equivalent to

  var rx = /[\S\s]/;

The pattern-match modifiers “(?s)” and “(?-s)" are also supported with a 
first String argument.  (But they apply to the rest of the expression, not 
only the current group, as of yet.)

This is particularly useful if you have many any-character occurrences in 
the expression.  The “.” will _not_ be expanded in a character class, so as 
to retain its original meaning:

  var rx = new jsx.regexp.RegExp(/.[.]./, "s");

is equivalent to

  var rx = /[\S\s][.][\S\s]/;

jsx.regexp.RegExp() is a factory/constructor that returns a reference to an 
augmented RegExp instance.  So from here everything in your script can stay 
the same (global, case-insensitive, multi-line, and other flags are 
supported by the function as well).  You may carefully import it into the 
global namespace, like

  jsx._import(jsx.regexp, ["RegExp"], null, ["RegExp2"]);  // [3]

or a variable declaration if you want to keep it efficient but local.

________
[1] <http://PointedEars.de/scripts/test/regexp>
[2] 
<http://pointedears.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fregexp.js>
[3] 
<http://pointedears.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fobject.js>
-- 
PointedEars

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

RegExp problem John English <john.foreign@gmail.com> - 2013-03-14 04:56 -0700
  Re: RegExp problem "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-03-14 14:22 +0200
    Re: RegExp problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-14 14:52 +0100
      Re: RegExp problem "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-03-14 16:08 +0200
      Re: RegExp problem Stefan Weiss <krewecherl@gmail.com> - 2013-03-14 15:25 +0100
        Re: RegExp problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-14 16:47 +0100
          Re: RegExp problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-14 21:11 +0100
        Re: RegExp problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-14 19:54 +0100
  Re: RegExp problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-14 13:26 +0100
  Re: RegExp problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-14 17:31 +0100

csiph-web