|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |