Skip to content

regexp: ReplaceAllFunc ReplaceAllStringFunc bad specification #6687

@gopherbot

Description

@gopherbot

by itcraft.letter:

Package regexp: http://golang.org/pkg/regexp/

bad specification of functions:
--
func (re *Regexp) ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte
func (re *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) string
--

correct specification of functions:
--
func (re *Regexp) ReplaceAllFunc(src []byte, repl func([][]byte) []byte) []byte
func (re *Regexp) ReplaceAllStringFunc(src string, repl func([]string) string) string
--

It is necessary to transfer in the function of the parts of regexp.
Example
reg := regexp.MustCompile(`#{(\w*)}#`)

replacer := func(partRegExp []string) string {
  //{$0} - partRegExp[0]
  //{$1} - partRegExp[1]
  // ...
}

fileSource = reg.ReplaceAllStringFunc(fileSource, replacer)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions