查找字符串Go中是否存在反斜杠

I have a string like this:

id=PS\\ Old\\ Gen

and I would to build a regex to find out if it contains a backslash; one after the other. So in this case, the regex should find 2 occurances as there are 2 \\.

I tried building up the query but couldn't figure out the right way.

i need the regex that's compatiable with Go.

You can use strings.Count(myString, \)

with literal example:

package main

import (
    "fmt"
    "strings"
)

func main() {
    myString := `id=PS\\Old\\Gen`
    a := `\`
    i := strings.Count(myString, a)
    fmt.Println(i)
}

result = 4

without literal

package main

import (
    "fmt"
    "strings"
)

func main() {
    myString := "id=PS\\Old\\Gen"
    a := `\`
    i := strings.Count(myString, a)
    fmt.Println(i)
}

Result=2

if you just need contain use

myString := "id=PS\\ Old\\ Gen"
a:=`\`
i := strings.Contains(myString, a)
fmt.Println(i)

Result=true

It sounds like you don't need to know the position or occurence of \\ so in that cause I'd suggest going as simple as possible:

import "strings"

...

fmt.Println(strings.Contains("id=PS\\ Old\\ Gen", "\\")) // true

So you can just store "\\" in your config.