-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
8u111
-
None
-
generic
-
generic
Hi
I stumbled upon a minor discrepancy between Nashorn and other
JavaScript engines when doing regexp matching with the multiline flag
enabled.
Nashorn
```
$ jjs -version
nashorn 1.8.0_111
jjs> String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
*a
*c
**
*e
```
Notice that the characters 'b' and 'd' are gone from the output.
Node:
```
$ node --version
v5.5.0
$ node
String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
'*a\n*b\r*c\n*\r*d\r*\n*e'
```
Firefox & Chrome console:
```
String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
"*a
*b
*c
*
*d
*
*e"
```
Notice that the characters 'b' and 'd' are in the output.
-
I suspect the cause is that nashorn does treat the character after
'\r' as being at the start of a line.
-
Esben
I stumbled upon a minor discrepancy between Nashorn and other
JavaScript engines when doing regexp matching with the multiline flag
enabled.
Nashorn
```
$ jjs -version
nashorn 1.8.0_111
jjs> String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
*a
*c
**
*e
```
Notice that the characters 'b' and 'd' are gone from the output.
Node:
```
$ node --version
v5.5.0
$ node
String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
'*a\n*b\r*c\n*\r*d\r*\n*e'
```
Firefox & Chrome console:
```
String.prototype.replace.apply("a\nb\rc\n\rd\r\ne", [/^(.*)/gm,"*$1"]);
"*a
*b
*c
*
*d
*
*e"
```
Notice that the characters 'b' and 'd' are in the output.
-
I suspect the cause is that nashorn does treat the character after
'\r' as being at the start of a line.
-
Esben