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


Groups > comp.lang.javascript > #18896

Re: RegExp problem

Message-ID <3460713.alAdkCt8v1@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-03-14 21:11 +0100
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>

Show all headers | 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