### Installation
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Install the go-sanitize package using go get.
```bash
go get -u github.com/mrz1836/go-sanitize
```
--------------------------------
### Development Setup
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Install MAGE-X build tool for development.
```bash
```
--------------------------------
### Install MAGE-X
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Installs MAGE-X for development and building.
```bash
go install github.com/mrz1836/mage-x/cmd/magex@latest
magex update:install
```
--------------------------------
### URI Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
An example demonstrating the usage of the URI function.
```go
input := "Test?=what! &this=that"
result := sanitize.URI(input)
fmt.Println(result) // Output: "Test?=what&this=that"
```
--------------------------------
### URL Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
An example demonstrating the usage of the URL function.
```go
input := "https://Example.com/This/Works?^No&this"
result := sanitize.URL(input)
fmt.Println(result) // Output: "https://Example.com/This/Works?No&this"
```
--------------------------------
### XML Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
An example demonstrating the usage of the XML function.
```go
input := `Something`
result := sanitize.XML(input)
fmt.Println(result) // Output: "Something"
```
--------------------------------
### Email Function Example (Default)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Example using Email() with default settings.
```go
Output:
person@example.com
```
--------------------------------
### SingleLine Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
An example demonstrating the usage of the SingleLine function.
```go
input := "This is a\nmulti-line\tstring."
result := sanitize.SingleLine(input)
fmt.Println(result) // Output: "This is a multi-line string."
```
--------------------------------
### Time Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
An example demonstrating the usage of the Time function.
```go
input := "t00:00d -EST"
result := sanitize.Time(input)
fmt.Println(result) // Output: "00:00"
```
--------------------------------
### ExampleXSS Example Output
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Output from an ExampleXSS example using XSS().
```text
>This?
```
--------------------------------
### XSS Function Usage Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example demonstrating the usage of the XSS function.
```go
input := ""
result := sanitize.XSS(input)
fmt.Println(result) // Output: ">alert('test');"
```
--------------------------------
### FirstToUpper Function Example Output
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Output of the FirstToUpper function example.
```go
Output:
This works
```
--------------------------------
### Basic Usage Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
A basic example demonstrating how to use the AlphaNumeric function for string sanitization.
```go
package main
import (
"fmt"
"github.com/mrz1836/go-sanitize"
)
func main() {
// Sanitize a string to remove unwanted characters
input := "Hello, World! @2025"
sanitized := sanitize.AlphaNumeric(input, false) // true to keep spaces
// Output: "Sanitized String: HelloWorld2025"
fmt.Println("Sanitized String:", sanitized)
}
```
--------------------------------
### ScientificNotation Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example usage of the ScientificNotation function.
```go
input := "The value is 1.23e+10 and 4.56E-7."
result := sanitize.ScientificNotation(input)
fmt.Println(result) // Output: "1.23e+104.56E-7"
```
--------------------------------
### Punctuation Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example usage of the Punctuation function to clean user input.
```go
input := "Hello, World! How's it going? (Good, I hope.) @2024"
result := sanitize.Punctuation(input)
fmt.Println(result) // Output: "Hello, World! How's it going? Good, I hope."
```
--------------------------------
### Email Function Example (PreserveCase)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Email function while preserving the original case.
```go
Output:
Person@Example.COM
```
--------------------------------
### Scripts Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example usage of the Scripts function to remove potentially harmful tags.
```go
input := ""
result := sanitize.Scripts(input)
fmt.Println(result) // Output: "alert('test');"
```
--------------------------------
### SafeHTML Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
An example of using a library like bluemonday for a more improved XSS prevention approach.
```go
import "github.com/microcosm-cc/bluemonday"
func SafeHTML(unsafe string) string {
p := bluemonday.UGCPolicy() // or build your own allow-list
return p.Sanitize(unsafe)
}
```
--------------------------------
### Domain Function Example (PreserveCase)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Domain function while preserving the original case.
```go
Output:
www.Example.COM
```
--------------------------------
### FirstToUpper Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the FirstToUpper function to capitalize the first letter of a string.
```go
input := "hello world"
result := sanitize.FirstToUpper(input)
fmt.Println(result) // Output: "Hello world"
```
--------------------------------
### Library Deployment
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Installs goreleaser for library deployment.
```bash
brew install goreleaser
```
--------------------------------
### PhoneNumber Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example usage of the PhoneNumber function to normalize a phone number.
```go
input := "+1 (234) 567-8900"
result := sanitize.PhoneNumber(input)
fmt.Println(result) // Output: "+12345678900"
```
--------------------------------
### Alpha Function Example (No Spaces)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Example of using the Alpha function without preserving spaces.
```text
Output:
ExampleString
```
--------------------------------
### Domain Function Example (RemoveWww)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Domain function to remove the 'www' subdomain.
```go
Output:
example.com
```
--------------------------------
### Alpha Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example usage of the Alpha function to sanitize a string, preserving spaces.
```go
input := "Hello, 世界! 123"
result := sanitize.Alpha(input, true)
fmt.Println(result) // Output: "Hello 世界"
```
--------------------------------
### Basic Usage
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
A basic example of how to use go-sanitize to remove unwanted characters from a string.
```go
package main
import (
"fmt"
"github.com/mrz1836/go-sanitize"
)
func main() {
// Sanitize a string to remove unwanted characters
input := "Hello, World! @2025"
sanitized := sanitize.AlphaNumeric(input, false) // true to keep spaces
// Output: "Sanitized String: HelloWorld2025"
fmt.Println("Sanitized String:", sanitized)
}
```
--------------------------------
### AlphaNumeric Function Example (No Spaces)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Example of using the AlphaNumeric function without preserving spaces.
```text
Output:
ExampleString2
```
--------------------------------
### Decimal Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Decimal function to sanitize a string containing a positive number.
```go
input := "The price is -123.45 USD"
result := sanitize.Decimal(input)
fmt.Println(result) // Output: "-123.45"
```
--------------------------------
### Domain Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Domain function to sanitize a domain name, converting to lowercase and removing 'www'.
```go
input := "www.Example.com"
result, err := sanitize.Domain(input, false, true)
if err != nil {
log.Fatal(err)
}
fmt.Println(result) // Output: "example.com"
```
--------------------------------
### Email Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Email function to sanitize an email address, removing 'MailTo:' prefix and converting to lowercase.
```go
input := "MailTo:Example@DOMAIN.com"
result := sanitize.Email(input, false)
fmt.Println(result) // Output: "example@domain.com"
```
--------------------------------
### AlphaNumeric Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example usage of the AlphaNumeric function to sanitize a string, preserving spaces.
```go
input := "Hello, 世界! 123"
result := sanitize.AlphaNumeric(input, true)
fmt.Println(result) // Output: "Hello 世界 123"
```
--------------------------------
### Decimal Function Example (Negative)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Example of using the Decimal function to sanitize a string containing a negative number.
```go
Output:
-99.99
```
--------------------------------
### BitcoinAddress Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Sanitizes a string to contain only valid characters for a Bitcoin address.
```go
input := "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa!@#"
result := sanitize.BitcoinAddress(input)
fmt.Println(result) // Output: "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
```
--------------------------------
### Custom Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Sanitizes a string using a custom regex string.
```go
input := "Hello, World! 123"
customRegExp := `[^a-zA-Z\s]`
result := sanitize.Custom(input, customRegExp)
fmt.Println(result) // Output: "Hello World"
```
--------------------------------
### CustomCompiled Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Sanitizes a string using a pre-compiled regular expression for better performance.
```go
input := "Hello, World! 123"
customRegExp := regexp.MustCompile(`[^a-zA-Z\s]`)
result := sanitize.CustomCompiled(input, customRegExp)
fmt.Println(result) // Output: "Hello World"
```
--------------------------------
### BitcoinCashAddress Function Example
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Sanitizes a string to contain only valid characters for a Bitcoin Cash address (cashaddr format).
```go
input := "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a!@#"
result := sanitize.BitcoinCashAddress(input)
fmt.Println(result) // Output: "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"
```
--------------------------------
### View All Build Commands
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Displays all available build commands.
```bash
magex help
```
--------------------------------
### Run All Tests (Fast)
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Executes all unit and fuzz tests.
```bash
magex test
```
--------------------------------
### Bump Version and Push
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Creates and pushes a new Git tag for releases.
```bash
magex version:bump bump=patch push
```
--------------------------------
### Run Go Benchmarks
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Executes the Go benchmarks for the library.
```bash
magex bench
```
--------------------------------
### Updating Dependencies
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Updates all dependencies including Go modules and linters.
```bash
magex deps:update
```
--------------------------------
### FormalName Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Demonstrates the usage of the FormalName function to sanitize a string for formal names.
```go
input := "John D'oe, Jr."
result := sanitize.FormalName(input)
fmt.Println(result) // Output: "John D'oe, Jr."
```
--------------------------------
### IPAddress Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Demonstrates the usage of the IPAddress function to sanitize an IP address string.
```go
input := "192.168.1.1!@#"
result := sanitize.IPAddress(input)
fmt.Println(result) // Output: "192.168.1.1"
```
--------------------------------
### Run All Tests with Race Detector
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Executes all tests with the race detector enabled.
```bash
magex test:race
```
--------------------------------
### PathName Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Demonstrates the usage of the PathName function to sanitize a string for use as a file or directory name.
```go
input := "file:name/with*invalid|chars"
result := sanitize.PathName(input)
fmt.Println(result) // Output: "filenamewithinvalidchars"
```
--------------------------------
### PathName Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Returns a sanitized string suitable for use as a file or directory name, removing invalid characters.
```go
func PathName(original string) string
```
```go
input := "file:name/with*invalid|chars"
result := sanitize.PathName(input)
fmt.Println(result) // Output: "filenamewithinvalidchars"
```
--------------------------------
### HTML Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Demonstrates the usage of the HTML function to remove HTML tags from a string.
```go
input := "Hello World!
"
result := sanitize.HTML(input)
fmt.Println(result) // Output: "Hello World!"
```
--------------------------------
### Numeric Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
Demonstrates the usage of the Numeric function to extract only numeric characters from a string.
```go
input := "Phone: 123-456-7890 ext. 42"
result := sanitize.Numeric(input)
fmt.Println(result) // Output: "123456789042"
```
--------------------------------
### IPAddress Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Returns a sanitized IP address string for both IPv4 and IPv6 formats, removing invalid characters.
```go
func IPAddress(original string) string
```
```go
input := "192.168.1.1!@#"
result := sanitize.IPAddress(input)
fmt.Println(result) // Output: "192.168.1.1"
```
--------------------------------
### ErrNilRegexp Variable
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
ErrNilRegexp indicates that a nil regular expression was provided.
```go
var ErrNilRegexp = errors.New("regular expression cannot be nil")
```
--------------------------------
### SingleLine Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The function signature for SingleLine, which sanitizes a string into a single line.
```go
func SingleLine(original string) string
```
--------------------------------
### FormalName Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Sanitizes a string to contain only characters recognized in formal names or surnames, supporting Unicode letters.
```go
func FormalName(original string) string
```
```go
input := "John D'oe, Jr."
result := sanitize.FormalName(input)
fmt.Println(result) // Output: "John D'oe, Jr."
```
--------------------------------
### Time Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The function signature for Time, which extracts the time part from a string.
```go
func Time(original string) string
```
--------------------------------
### Numeric Function
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize#section-readme
Returns a string containing only numeric characters (0-9) from the input, supporting Unicode digit runes.
```go
func Numeric(original string) string
```
```go
input := "Phone: 123-456-7890 ext. 42"
result := sanitize.Numeric(input)
fmt.Println(result) // Output: "123456789042"
```
--------------------------------
### URL Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The function signature for URL, which sanitizes a string to contain only valid URL characters.
```go
func URL(original string) string
```
--------------------------------
### URI Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The function signature for URI, which sanitizes a string to contain only valid URI characters.
```go
func URI(original string) string
```
--------------------------------
### XML Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The function signature for XML, which removes all XML tags from a string.
```go
func XML(original string) string
```
--------------------------------
### Punctuation Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The Punctuation function sanitizes a string to contain only alphanumeric characters and common punctuation.
```go
func Punctuation(original string) string
```
--------------------------------
### ScientificNotation Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The ScientificNotation function sanitizes a string to contain only valid characters for scientific notation.
```go
func ScientificNotation(original string) string
```
--------------------------------
### Scripts Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The Scripts function removes all script, iframe, embed, and object tags from the input string.
```go
func Scripts(original string) string
```
--------------------------------
### XSS Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The XSS function removes known XSS attack strings or script strings from the input.
```go
func XSS(original string) string
```
--------------------------------
### PhoneNumber Function Signature
Source: https://pkg.go.dev/github.com/mrz1836/go-sanitize
The PhoneNumber function sanitizes a string to contain only numeric digits and the plus sign (+).
```go
func PhoneNumber(original string) string
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.