Replace all instances of a pattern with regular expressions in Javascript / jQuery

前端 未结 2 1690
执笔经年
执笔经年 2021-01-20 00:33

First off I don\'t know much about regex and need to buy a book because it\'s has proven to me to be difficult to pickup.

Ultimately I want to take a dom element, an

2条回答
  •  醉梦人生
    2021-01-20 00:50

    .replace(/\[([^\]]*)\]/g, link + "$1")
    

    which means, find text between [ and ] and replace it with the value of link, the text itself and ''. This ensures matching square brackets. The 'g' means 'do it multiple times (globally)'.

提交回复
热议问题