javascript - How to Grab Selected str.replace Value From Regex in JS -
ok, understand how title might bit confusing, let me elaborate. start making bbcode input section. transfer code bbcode html. problem having minimal issues. let me post code before continue:
var newer = $('#my_textarea').val().replace(/\[b\]/gi, '<b>'); now let me this, replaces [b] tags correctly <b> tags. problem not know how tags. have tried shortening code using this:
var newer = $('#my_textarea').val().replace(/\[(?:b|u|i)\]/gi, '<???>'); then replace tags (bold, underline, , italicize) correct html tags. yet how go doings this? how replace html tag the bbcode tag found? mean part of regex (?:b|u|i) selects of 3 letters, how add same letter html tag? understand problem is? :) please help, thank you!!
use $2 second selected group
var newer = $('#my_textarea').val().replace(/(\[(b|u|i)\])/gi, '<$2>'); a site understanding , creating regex: https://regex101.com/
to catch [b],[u],[i] , [\b],[\u],[\i] use following:
var newer = $('#my_textarea').val().replace(/(\[((\/?)(b|u|i))\])/gi, '<$2>');
Comments
Post a Comment