POV-Ray : Newsgroups : povray.off-topic : Mini-languages : Re: Mini-languages Server Time
3 Sep 2024 21:14:08 EDT (-0400)
  Re: Mini-languages  
From: Nicolas Alvarez
Date: 27 Nov 2010 22:55:30
Message: <4cf1d2b2$1@news.povray.org>
Invisible wrote:
> "Syntactically JavaScript resembles Java with some influence from Perl,
> and features Perl-like regular expressions."
> 
> Since when does JS have regular expressions?

Like in Java, you can create a regular expression object with normal
object-creation syntax, using the RegExp class:

var regex = new RegExp("I( have|'ve) never seen ([^.,]*)");
var text = "I've never seen a system that can do that, but...";
return "he says he has never seen " + text.match(regex)[2];

But Javascript also has regex literals built into the language:

return "he says he has never seen " +
   text.match(/I( have|'ve) never seen ([^.,]*)/)[2];

(both return "Invisible has never seen a system that can do that")


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.