Skip to content Skip to sidebar Skip to footer

Making A Pipe With Regex On Angular2

I've already asked the similar question here: stackoverflow.com/questions/42674096/how-to-make-a-pipe-with-regex-in-angular2/ Now, I did try the following from the given answer: im

Solution 1:

You are running a loop with a regex that does not contain a /g (global modifier). That means, that each time your regex finds a match, the lastIndex property will not change, and during the next iteration, the same match will be found, and so on and so forth, causing an infinite loop.

See String#exec documentation at MDN:

lastIndex     The index at which to start the next match. When "g" is absent, this will remain as 0.

Use

let reg = /\([^)]+\)/g;

It will match all occurrences of (, then 1+ chars other than ) and then a ).

Post a Comment for "Making A Pipe With Regex On Angular2"