views:

63

answers:

1

I have detect a strange behavior in regexps created with the RegExp object:

With this code:

var exp1 = /./;
var exp2 = new RegExp('.');
​
var test1 = exp1.test('large\n\ntext..etc.');
var test2 = exp2.test('large\n\ntext..etc.');
​
var match1 = 'large\n\ntext..etc.'.match(exp1);
var match2 = 'large\n\ntext..etc.'.match(exp2);

...the result is:

test1 = true
test2 = true
​
match1 = 'l' (first match)
match2 = null

With the regexp maked with the regexp object from a string it finds nothing...

Why does this happends?

Thanks!!

EDIT: I have tried it in Mozilla Firefox 3.5, I haven't tried in other browsers...

+1  A: 

Works for me in Firefox 3.5.9. test1 and test2 are both true, and match1 and match2 are both ['l']

Matthew Flaschen
I have edited the main message. I tried it in Mozilla Firefox 3.5, I haven't tried in other browsers... Thanks for reply.
NeDark
Works for me as well: FF 3.6.3
Justin Johnson