I want to check the string between {}
in my statement, in JavaScript I can use:
Negative Lookahead to matches characters of the A to Z range as [a-zA-Z]+(?![^{]*\})
Or Negated Match if words will include whitespace or have other characters that need to be allowed or unsure of the type of input as [^}]+(?![^{]*\})
Here is a live example to check the below text
{con}descens{ion}
lumberjack
tim{ing}
{tox}{icity}
fish
{dis}pel
I tried to do same in GO as;
package main
import (
"fmt"
"regexp"
)
func main() {
r, err := regexp.Compile('[a-zA-Z]+(?![^{]*\})')
if err != nil {
fmt.Println(err)
return
}
fmt.Println(r.ReplaceAllString(`{con}descens{ion}
lumberjack
tim{ing}
{tox}{icity}
fish
{dis}pel`,
"found this"))
}
But got the below error:
# command-line-arguments
.\reg.go:9:46: unknown escape
I used below to get everything between {}
, is there a way to reverse it, i.e. select characters not match with this selection?
re := regexp.MustCompile("{([^{}]*)}") // start by {, end by }, contains any character except { and } [^{}]