|  |  | Nicolas Alvarez wrote:
> 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")
Er, of course I mean both return "he says he has never seen a system that 
can do that". I replaced "Invisible" in the input texts and didn't change it 
in the last line.
(I was planning to write a regex to find "is obviously impossible", but then 
couldn't find any good sample text in the p.o-t messages still in the 
server; looks like they really did beat that out of your vocabulary :P)
Post a reply to this message
 |  |