How to replace the characters !@#$%^*_+\= in a string using RegEx with Go

1 Answer

0 votes
package main

import (
    "fmt"
    "regexp"
)

func main() {
    inputText := "The!quick@brown#fox$jumps%^over*_the+\\lazy=dog."
    pattern := regexp.MustCompile(`[!@#$%^*_+=\\]`)
    replacement := " "

    // Perform regex replacement
    result := pattern.ReplaceAllString(inputText, replacement)

    fmt.Println("Original:", inputText)
    fmt.Println("Modified:", result)
}



/*
run:

Original: The!quick@brown#fox$jumps%^over*_the+\lazy=dog.
Modified: The quick brown fox jumps  over  the  lazy dog.

*/

 



answered Jun 11, 2025 by avibootz
...