ds1379551
2019-02-20 21:55
浏览 1.0k
已采纳

Golang正则表达式替换字符串之间

I have some strings in the following possible forms:

MYSTRING=${MYSTRING}

MYSTRING=

MYSTRING=randomstringwithvariablelength

I want to be able to regex this into MYSTRING=foo, basically replacing everything between MYSTRING= and . I've tried:

re := regexp.MustCompile("MYSTRING=*
")
s = re.ReplaceAllString(s, "foo")

But it doesn't work. Any help is appreciated.


P.S. the is to indicate that there's a newline for this purpose. It's not actually there.

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

我有以下形式的一些字符串:</ p>

   MYSTRING = $ {MYSTRING} 
 
MYSTRING = 
 
MYSTRING =具有可变长度的随机字符串
 
 </ code> </ pre> 
 
 

我希望能够将此表达式正则表达式化为 MYSTRING = foo </ code>,基本上替换了 MYSTRING = </ code>和 </ code>之间的所有内容。 我尝试过:</ p>

  re:= regexp.MustCompile(“ MYSTRING = * 
”)
s = re.ReplaceAllString(s,“ foo”)
 <  / code> </ pre> 
 
 

,但是它不起作用。 感谢您的任何帮助。</ p>


P.S。 </ code>表示为此目的有一个换行符。 它实际上不在那里。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题