Firstly, I know little about regular expression and you need to buy a book because it seemed to me that it was difficult to pick me up.
Ultimately, I want to take the dom element and replace the text in brackets "[" and "]" and insert a link around the text, and there can be several sets of brackets in the line.
function changeTip() { var link = '<a href="' + $('#txtURL').attr('value') + '" target="_blank">'; $('.tipoftheweektip').html($('#txtTip').attr("value").replace('[', link).replace(']', '</a>')); }
This works, with the exception of:
- does not work in the second set of brackets
- If there is no closing brace, it deletes all text before opening the brace
I reviewed the examples and because the regular expressions code uses straight brackets, I cannot figure out how to search for a bracket and replace it.
Anyone who has done something like this that they can share? Thanks in advance.
source share