Created
August 24, 2020 14:45
-
-
Save varphone/46a4a513cce2d3bc10e6b416804c72c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"regexp" | |
) | |
func main() { | |
fmt.Println("Hello, playground") | |
str := []byte("[](https://jenkins.com/job/aka/{{BRANCH_NAME}}/buildStatus)"); | |
vars := map[string][]byte{"BRANCH_NAME": []byte("master")}; | |
r, _ := regexp.Compile("{{\\s?([0-9,A-Z_]+)\\s?}}"); | |
m := r.FindAllSubmatch(str, -1); | |
fmt.Println(m); | |
for _, v := range m { | |
k := string(v[1]); | |
fmt.Println(k); | |
if val, found := vars[k]; found { | |
str = r.ReplaceAll(str, val); | |
delete(vars, k); | |
fmt.Println("Found"); | |
} | |
} | |
fmt.Println(string(str)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment