Answer the question
In order to leave comments, you need to log in
How to rewrite regex from js to golang?
Hello. js has regular expressions
var key = "test";
html = html.replace(new RegExp("{{"+key+"}}","g"), key);
if_array = html.match(/<if>(.*?)<\/if>/g);
<if></if>
puts all the data between the tags into an array [data1, data2, data3]
Answer the question
In order to leave comments, you need to log in
package main
import (
"fmt"
"regexp"
)
func main() {
html := "{{test}}ing <if>abc</if> {{test}} <if>123</if>"
key := "test"
html = regexp.MustCompile("{{"+key+"}}").ReplaceAllString(html, key)
array_temp := regexp.MustCompile("<if>(.*?)</if>").FindAllStringSubmatch(html, -1)
var if_array []string
for _, val := range array_temp {
if_array = append(if_array, val[1])
}
fmt.Println(html)
fmt.Println(if_array)
}
But... there are two regulars!
https://regex101.com/r/uG5bA6/1
https://regex101.com/r/uG5bA6/2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question