Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20322
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Identifying a regex |
| Date | 2013-06-17 14:05 +0200 |
| Organization | albasani.net |
| Message-ID | <kpmu20$5q5$1@news.albasani.net> (permalink) |
| References | <kplir9$pj9$1@news.albasani.net> <3c26ff4d-3b91-4784-bea9-20740208b338@x4g2000yqk.googlegroups.com> |
On 2013-06-17 04:30, Michael Haufe (TNO) wrote:
> On Jun 16, 6:47 pm, Stefan Weiss <krewech...@gmail.com> wrote:
>> What do you think is the best way to identify a value as a regular
>> expression (reference to a RegExp object)? [...]
...
> Assuming you want to avoid a combination of the above techniques,
> regular expressions also have a 'source' property that cannot be
> changed directly. So...
I'm not sure if a combination of techniques would help. Wouldn't both
the false positives and false negatives just add up?
> function isRe(re){
> var s = re.source
> re.source = s + "foo"
> var p = (s == re.source)
> if(!p) re.source = s //restore just in case
> return p
> }
That's duck typing (of a sort), but more invasive than usual. For
example, when you call this function with a plain empty object ({}), it
will have a "source" property afterwards. It's also not safe to assume
that changing a property to a new value and then changing it back will
restore the object to its original state. And lastly, there are valid
reasons to create other (non-regex) objects with an immutable "source"
property.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web