c# - Regular expression find and replace to wrap tags -
does know how use regex find , replace word with
<b>[keyword]</b>
i tried use regex.replace()
seems support direct replacement instead of appending <b></b>
@ begin , last of keyword.
example:
hello world!
keyword:
hello
output:
<b>hello</b> world!
you may try this:
using system; using system.text.regularexpressions; class program { static void main(string[] args) { string input = "hello world!", keyword = "hello"; var result = regex .replace(input, keyword, m => string.format("<b>{0}</b>", m.value)); console.writeline(result); } }
Comments
Post a Comment