最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript regex shorthand? - Stack Overflow

programmeradmin2浏览0评论

I'm trying to enjoy some of the awesome javascript code golf submissions on anarchy code golf, but I keep seeing things like:

for(;s=readline();)print("h"+/t.*/(s))

...which was the JS winner for: .rb?ttp

I don't understand how that is correct javascript syntax, and I even tried resubmitting that, but it said object is not a function, which is something along the lines of what I would expect to happen.

Was this some kind of glitch or shorthand or something in an older javascript version?

I'm trying to enjoy some of the awesome javascript code golf submissions on anarchy code golf, but I keep seeing things like:

for(;s=readline();)print("h"+/t.*/(s))

...which was the JS winner for: http://golf.shinh/p.rb?ttp

I don't understand how that is correct javascript syntax, and I even tried resubmitting that, but it said object is not a function, which is something along the lines of what I would expect to happen.

Was this some kind of glitch or shorthand or something in an older javascript version?

Share Improve this question asked Feb 6, 2012 at 23:36 mowwwalkermowwwalker 17.4k30 gold badges108 silver badges165 bronze badges 1
  • It looks like /t.*/ creates a regex object and applies it to the string in s, and then appends "h" to the front. I wouldn't know whether /t.*/(s) syntax is valid though. – mathematical.coffee Commented Feb 7, 2012 at 1:33
Add a ment  | 

1 Answer 1

Reset to default 13

Was this some kind of glitch or shorthand or something in an older javascript version?

More or less, yes. According to that site's version info, it uses SpiderMonkey (Mozilla's JavaScript engine), which used to have the feature that regular-expression objects were callable; that is, that if re was a regular-expression object, then re(...) was equivalent to re.exec(...). That feature was removed in this change, a result of Bug 582717, and that site has since updated to a version that incorporates that removal.

发布评论

评论列表(0)

  1. 暂无评论