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


Groups > comp.lang.javascript > #20313 > unrolled thread

Identifying a regex

Started byStefan Weiss <krewecherl@gmail.com>
First post2013-06-17 01:47 +0200
Last post2013-06-18 21:14 +0200
Articles 4 on this page of 24 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 01:47 +0200
    Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-16 19:30 -0700
      Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 14:05 +0200
        Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-17 16:16 -0700
          Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 02:13 +0200
            Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 20:14 +0200
              Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 21:39 +0200
                Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 23:58 +0200
                  Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-25 22:05 +0200
                    Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-25 16:59 -0700
                      Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-26 23:47 +0200
                Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-23 20:01 +0200
          Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-18 00:40 -0700
            Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 10:39 +0200
              Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-18 19:32 -0700
                Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-19 14:05 +0200
                  Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-19 20:24 -0700
                    Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-20 12:27 +0200
                      Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-20 18:08 -0700
    Re: Identifying a regex JJ <duh@nah.meh> - 2013-06-17 13:58 +0700
      Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 14:11 +0200
        Re: Identifying a regex JJ <duh@nah.meh> - 2013-06-18 12:46 +0700
          Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 20:17 +0200
    Re: Identifying a regex Andreas Bergmaier <andber93@web.de> - 2013-06-18 21:14 +0200

Page 2 of 2 — ← Prev page 1 [2]


#20323

FromStefan Weiss <krewecherl@gmail.com>
Date2013-06-17 14:11 +0200
Message-ID<kpmudk$6ik$1@news.albasani.net>
In reply to#20318
On 2013-06-17 08:58, JJ wrote:
> On Mon, 17 Jun 2013 01:47:53 +0200, Stefan Weiss wrote:
>> What do you think is the best way to identify a value as a regular
>> expression (reference to a RegExp object)? I can see at least four
>> different ways, each with its own drawbacks:
>> 
>>   A) val instanceof RegExp
>>   B) val.constructor.name == "RegExp"
>>   C) Object.prototype.toString.call(val) == "[object RegExp]"
>>   D) duck typing
> 
> I've been using this kind of duck. Does it have a defect?
> 
> isNativeCode = /\{[ \n]+\[native code\][ \n]+\}$/im;
> isRegExp = (val instanceof RegExp) &&
>   isNativeCode.test(RegExp) && isNativeCode.test(RegExp.toString);

I don't understand what you're doing here...

The first test (val instanceof RegExp) is the method (A) I mentioned
earlier, and it will suffer from the same problem (cross-frame
identification).
The other tests just check the native RegExp object, not the value.


- stefan

[toc] | [prev] | [next] | [standalone]


#20329

FromJJ <duh@nah.meh>
Date2013-06-18 12:46 +0700
Message-ID<1i7d70t86bl5s$.1v6joqq8jnd0n.dlg@40tude.net>
In reply to#20323
On Mon, 17 Jun 2013 14:11:31 +0200, Stefan Weiss wrote:
> I don't understand what you're doing here...
> 
> The first test (val instanceof RegExp) is the method (A) I mentioned
> earlier, and it will suffer from the same problem (cross-frame
> identification).
> The other tests just check the native RegExp object, not the value.

Assuming RegExp has not been modified in both windows, shouldn't this be
true?

window1.RegExp === window2.RegExp

[toc] | [prev] | [next] | [standalone]


#20333

FromStefan Weiss <krewecherl@gmail.com>
Date2013-06-18 20:17 +0200
Message-ID<kpq874$o40$2@news.albasani.net>
In reply to#20329
On 2013-06-18 07:46, JJ wrote:
> Assuming RegExp has not been modified in both windows, shouldn't this be
> true?
> 
> window1.RegExp === window2.RegExp

No, this evaluates to false (unless window1 == window2).

- stefan

[toc] | [prev] | [next] | [standalone]


#20334

FromAndreas Bergmaier <andber93@web.de>
Date2013-06-18 21:14 +0200
Message-ID<kpqbip$vp8$1@news.albasani.net>
In reply to#20313
Stefan Weiss schrieb:
> What do you think is the best way to identify a value as a regular
> expression (reference to a RegExp object)? I can see at least four
> different ways, each with its own drawbacks:
>
> […]
> B) val.constructor.name == "RegExp"
> […]
 > The constructor property can be changed manually at any time.

The bigger drawback I see is that `name` is a non-standard property. 
Most notably, it doesn't exist in Internet Explorer.

The only workaround I could find seems to be parsing it out of the 
.toString() representation, which again does not work in all environments.

  Bergi

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web