github.com/blend/go-sdk@v1.20220411.3/sourceutil/match.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package sourceutil 9 10 import ( 11 "fmt" 12 "regexp" 13 ) 14 15 // MatchRemove removes a line if it matches a given expression. 16 func MatchRemove(corpus []byte, expr string) []byte { 17 compiledExpr := regexp.MustCompile(expr) 18 return compiledExpr.ReplaceAll(corpus, nil) 19 } 20 21 // MatchInject injects a given value after the any instances of a given expression. 22 func MatchInject(corpus []byte, expr, inject string) []byte { 23 compiledExpr := regexp.MustCompile(expr) 24 return compiledExpr.ReplaceAll(corpus, []byte(fmt.Sprintf("$0\n%s\n", inject))) 25 }