2015-07-28 14:53
浏览 213

带有反向引用的golang regexp ReplaceAllStrings不太起作用

Trying to capitalize each letter at begin of the word. I know that there is strings.Title, but that is too imprecise for my needs.

I am not sure why this does not work:

package main

import (

func main() {
    re := regexp.MustCompile(`\b([a-z])`)
    fmt.Println(re.ReplaceAllString("my test string", strings.ToUpper("$1")))


图片转代码服务由CSDN问答提供 功能建议

尝试在单词开头将每个字母大写。 我知道有 strings.Title </ code>,但这对于我的需求来说太不精确了。 </ p>

我不确定为什么这行不通:</ p>

  package main 
“ fmt” 
“  regexp“ 
” strings“ 
func main(){
 re:= regexp.MustCompile(`\ b([az])`)
 fmt.Println(re.ReplaceAllString(” my test 字符串”,strings.ToUpper(“ $ 1”)))
 </ code> </ pre> </ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题