R
runsun pan
Hi
I am wondering why I couldn't get what I want in the following 3 cases
of re:
(A)
var p=/([a-zA-Z]+-?[a-zA-Z]+)[a-zA-Z0-9]+)/g
p.exec("style='font-size:12'")
--> [font-size:12,font-size,12] // expected
(B)
p.exec("style='font-size:12;border-color:red'")
--> [border-color:red,border-color,red]
// expected: [font-size:12,font-size,12,
border-color:red,border-color,red]
(C) Note the pattern below is the same as that above:
/([a-zA-Z]+-?[a-zA-Z]+)[a-zA-Z0-9]+)/g.exec("style='font-size:12;border-color:red'")
--> [font-size:12,font-size,12]
I expected to get both font-size and border-color reported. However, in
case (B) only border-color is reported, and in case (C) only font-size
reported. The weirdest thing is that (B) and (C) are only different in
how it is used -- in (B) the pattern is assigned to a variable before
use, in (C) the pattern is used directly.
I am wondering why I couldn't get what I want in the following 3 cases
of re:
(A)
var p=/([a-zA-Z]+-?[a-zA-Z]+)[a-zA-Z0-9]+)/g
p.exec("style='font-size:12'")
--> [font-size:12,font-size,12] // expected
(B)
p.exec("style='font-size:12;border-color:red'")
--> [border-color:red,border-color,red]
// expected: [font-size:12,font-size,12,
border-color:red,border-color,red]
(C) Note the pattern below is the same as that above:
/([a-zA-Z]+-?[a-zA-Z]+)[a-zA-Z0-9]+)/g.exec("style='font-size:12;border-color:red'")
--> [font-size:12,font-size,12]
I expected to get both font-size and border-color reported. However, in
case (B) only border-color is reported, and in case (C) only font-size
reported. The weirdest thing is that (B) and (C) are only different in
how it is used -- in (B) the pattern is assigned to a variable before
use, in (C) the pattern is used directly.