Home » Javascript » How to replace the variable's pattern using regex in Javascript

How to replace the variable's pattern using regex in Javascript

Posted by: admin August 19, 2018 Leave a comment

Questions:

I want to make every |x| be replaced by [axb] in Javascript, the length of x is more than 0.

For example:

Input var i="|12|3|4|5||"

Output should be [a12b]3[a4b]5||

Answers: