go – Regex for replace a string
I have a func. in which I need to replace my html body tag like :
const htmlTags = <html><body x=1>Demo-x1</body><html>
with <html><body x=1>Demo-x1 My new test</body><html>
Here is the program snippet.
const htmlTags = "`<html[^>]*>(.*?)</html>|<body[^>]*>(.*?)</body>/is`"
var htmlRegexp = regexp.MustCompile(htmlTags)
var new_html = "<h1>DEMO</h1>"
my.Response.Body = htmlRegexp.ReplaceAll(my.Response.Body, []byte("$1"+new_html+"$2"))
Nothing happened, but if I change my htmlTages with (<title>)(.*?)(</title>) and []byte("$1"+new_html+"$2") with []byte("$1"+new_html+"$3" my title is changing.
Any solutions for successfully getting the desired result?
Read more here: Source link
