Why does this line crash Javascript?

This line in Chrome / NodeJS crashes. Why?

In Chrome, it causes the browser tab to hang without an error message.

"www.asite.com/clothes-intimates-bras-bralettes/sub5-sub6-sub7-sub8".replace(/.*?([\w\s-]*)+\/?$/, 'www.asite.com/product/$1')
+4
source share
1 answer

This can help examine your regular expression in detail to understand what is going on. Here is the original.

.*?([\w\s-]*)+\/?$

And the breakdown:

.*?

. = anything * = zero or more, and? = not greedy.

([\w\s-]*)+

() = capture, [] = group, \ w = alphanumerics, \ s = spaces, - = dashes, * = zero or more, + = one or more.

\/?

? = may or may not happen.

, , , -, , , , ​​, , , . .* ([\w\s-]*)+ , .

null ( ) , -sub8, www.asite.com/clothes-intimates-bras-bralettes/sub5-sub6-sub7-sub8. . *? , 7000 ([\ w\s-] *) ( * ), ([\ w\s-] *) "8"... , , ([] *)+.

, -, , . ?

+3

Source: https://habr.com/ru/post/1542266/


All Articles