regex and javascript, some matches disappear !

Posted by dader51 on Stack Overflow See other posts from Stack Overflow or by dader51
Published on 2010-05-12T15:30:10Z Indexed on 2010/05/12 15:34 UTC
Read the original article Hit count: 285

Here is the code :

> var reg = new RegExp(" hel.lo ", 'g');
> 
> var str = " helalo helblo helclo heldlo ";
> 
> var mat = str.match(reg);
> 
> alert(mat);

It alerts "helalo, helclo", but i expect it to be "helalo, helblo, helclo, heldlo" . Only the half of them matches, I guess that's because of the space wich count only once. So I tried to double every space before processing, but in some case it's not enough. I'm looking for an explanation, and a solution.

Thx

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex