ast wrote:
> let us search a.+b in string abcabcabc
>
> var reg = /a.+b/g;
> var tab = reg.exec("abcabcabc");
>
> document.write(tab[0]);
>
> there are 2 possible matchs:
>
> abcab
> abcabcab
>
> javascript choose the second one. Why not. But what is the rule ?
> Does javascript always provide the longest possible match ?
(There is no "javascript".)
Yes, RTFM. Regular expressions are "greedy" by default.
> If i want abcab, is there something to do ?
RTFM.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
|