Golang : unknown escape sequence error
Encountered a funky error message unknown escape sequence while working this the tutorial on how to find IP address from a string. Apparently, Go doesn't like this statement :
regexPattern := numBlock + "\." + numBlock + "\." + numBlock + "\." + numBlock
and to fix the error, I've to escape the backslash.
regexPattern := numBlock + "\\." + numBlock + "\\." + numBlock + "\\." + numBlock
alternatively, backtick ` can be used to fix the error as well.
regexPattern := numBlock + `\.` + numBlock + `\.` + numBlock + `\.` + numBlock
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.3k Golang : Variadic function arguments sanity check example
+17.8k Convert JSON to CSV in Golang
+42.3k Golang : How do I convert int to uint8?
+14.7k Golang : How to get URL port?
+7.1k Golang : Calculate BMI and risk category
+19.9k Golang : Get current URL example
+9.6k Golang : Scramble and unscramble text message by randomly replacing words
+13.6k Golang : Get constant name from value
+9.8k Golang : Populate slice with sequential integers example
+7.3k Golang : Gargish-English language translator