I have one use case where I can have a text string which can contain anything. What I want to achieve is to replace a certain pattern within that given string.
Let's say I have given string as
:es1
es2
aaes1aa
:es3,
es1:
ees1,
ees1
{
"es1 :
What I am trying to do is here is suppose I have to replace all es1 in this string but with one condition. It has to be either end or start with [, | ; | : | " | ' | \\ | \s]. :es1, es1,, es1: and so on are accepted but eees1sss is not.
I tried ([, | ; | : | " | ' | \\ | \s])(es1)([, | ; | : | " | ' | , | \s]) something like this but I don't think it's what I need.
Go program:
match := regexp.MustCompile(`([, | ; | : | " | ' | \\ | \s])(es1)([, | ; | : | " | ' | , | \s])`)
test := `:es1
es2
aaes1aa
:es3,
es1:
ees1,
ees1
{
"es1 :`
fmt.Println(match.ReplaceAllString(test, "$1es4$3"))
output:
es2
aaes1aa
:es3,
:
ees1,
ees1
{
:
I was expecting my output to be more like
:es4
es2
aaes1aa
:es3,
es4:
ees1,
ees1
{
"es4 :
e:es1?es1: .....some text. ..:es1