mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Support regex capture groups in replace command
See https://golang.org/pkg/regexp/syntax/ for the supported syntax. Here are some examples: ``` replace "(foo)" "$1-bar" replace "(foo)" "${1}-bar" replace "(?P<group>foo)" "$group-bar" replace "(?P<group>foo)" "$group-bar" replace "(?P<key>\w+):\s+(?P<value>\w+)$" "$key=$value" ``` Closes #1115
This commit is contained in:
@@ -155,8 +155,12 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b
|
||||
l = util.SliceStart(l, end.X)
|
||||
}
|
||||
newText := search.ReplaceAllFunc(l, func(in []byte) []byte {
|
||||
result := []byte{}
|
||||
for _, submatches := range search.FindAllSubmatchIndex(in, -1) {
|
||||
result = search.Expand(result, replace, in, submatches)
|
||||
}
|
||||
found++
|
||||
return replace
|
||||
return result
|
||||
})
|
||||
|
||||
from := Loc{charpos, i}
|
||||
|
||||
Reference in New Issue
Block a user