how to solve the error of `unknown escape sequence (and 2 more errors)`












-1














I m trying to validate the image url using golang code but there is error in regular expression I'm showing my regular expression in this question:-



 var validation = regexp.MustCompile("(http(s?):)|([/|.|w|s])*.(?:jpg|gif|png)")


Error:-




unknown escape sequence (and 2 more errors)




play link










share|improve this question






















  • I'd suggest using backtics when defining regex so that you won't have to escape ""
    – ssemilla
    Nov 17 '18 at 9:51












  • @ssemilla can you tell me what corrections
    – stack
    Nov 17 '18 at 9:52










  • Replace " with `. I didn't actually review your regex but people usually make mistakes when they mean "\" rather than "". Using backtics instead makes it very clear what we mean since nothing is escaped.
    – ssemilla
    Nov 17 '18 at 9:52












  • @ssemilla By using ` instead of " it runs but not working properly it prints nothing
    – stack
    Nov 17 '18 at 9:55












  • Why are you using !validation.MatchString() instead of just validation.MatchString()?
    – ssemilla
    Nov 17 '18 at 9:58
















-1














I m trying to validate the image url using golang code but there is error in regular expression I'm showing my regular expression in this question:-



 var validation = regexp.MustCompile("(http(s?):)|([/|.|w|s])*.(?:jpg|gif|png)")


Error:-




unknown escape sequence (and 2 more errors)




play link










share|improve this question






















  • I'd suggest using backtics when defining regex so that you won't have to escape ""
    – ssemilla
    Nov 17 '18 at 9:51












  • @ssemilla can you tell me what corrections
    – stack
    Nov 17 '18 at 9:52










  • Replace " with `. I didn't actually review your regex but people usually make mistakes when they mean "\" rather than "". Using backtics instead makes it very clear what we mean since nothing is escaped.
    – ssemilla
    Nov 17 '18 at 9:52












  • @ssemilla By using ` instead of " it runs but not working properly it prints nothing
    – stack
    Nov 17 '18 at 9:55












  • Why are you using !validation.MatchString() instead of just validation.MatchString()?
    – ssemilla
    Nov 17 '18 at 9:58














-1












-1








-1







I m trying to validate the image url using golang code but there is error in regular expression I'm showing my regular expression in this question:-



 var validation = regexp.MustCompile("(http(s?):)|([/|.|w|s])*.(?:jpg|gif|png)")


Error:-




unknown escape sequence (and 2 more errors)




play link










share|improve this question













I m trying to validate the image url using golang code but there is error in regular expression I'm showing my regular expression in this question:-



 var validation = regexp.MustCompile("(http(s?):)|([/|.|w|s])*.(?:jpg|gif|png)")


Error:-




unknown escape sequence (and 2 more errors)




play link







go






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 17 '18 at 9:45









stack

105




105












  • I'd suggest using backtics when defining regex so that you won't have to escape ""
    – ssemilla
    Nov 17 '18 at 9:51












  • @ssemilla can you tell me what corrections
    – stack
    Nov 17 '18 at 9:52










  • Replace " with `. I didn't actually review your regex but people usually make mistakes when they mean "\" rather than "". Using backtics instead makes it very clear what we mean since nothing is escaped.
    – ssemilla
    Nov 17 '18 at 9:52












  • @ssemilla By using ` instead of " it runs but not working properly it prints nothing
    – stack
    Nov 17 '18 at 9:55












  • Why are you using !validation.MatchString() instead of just validation.MatchString()?
    – ssemilla
    Nov 17 '18 at 9:58


















  • I'd suggest using backtics when defining regex so that you won't have to escape ""
    – ssemilla
    Nov 17 '18 at 9:51












  • @ssemilla can you tell me what corrections
    – stack
    Nov 17 '18 at 9:52










  • Replace " with `. I didn't actually review your regex but people usually make mistakes when they mean "\" rather than "". Using backtics instead makes it very clear what we mean since nothing is escaped.
    – ssemilla
    Nov 17 '18 at 9:52












  • @ssemilla By using ` instead of " it runs but not working properly it prints nothing
    – stack
    Nov 17 '18 at 9:55












  • Why are you using !validation.MatchString() instead of just validation.MatchString()?
    – ssemilla
    Nov 17 '18 at 9:58
















I'd suggest using backtics when defining regex so that you won't have to escape ""
– ssemilla
Nov 17 '18 at 9:51






I'd suggest using backtics when defining regex so that you won't have to escape ""
– ssemilla
Nov 17 '18 at 9:51














@ssemilla can you tell me what corrections
– stack
Nov 17 '18 at 9:52




@ssemilla can you tell me what corrections
– stack
Nov 17 '18 at 9:52












Replace " with `. I didn't actually review your regex but people usually make mistakes when they mean "\" rather than "". Using backtics instead makes it very clear what we mean since nothing is escaped.
– ssemilla
Nov 17 '18 at 9:52






Replace " with `. I didn't actually review your regex but people usually make mistakes when they mean "\" rather than "". Using backtics instead makes it very clear what we mean since nothing is escaped.
– ssemilla
Nov 17 '18 at 9:52














@ssemilla By using ` instead of " it runs but not working properly it prints nothing
– stack
Nov 17 '18 at 9:55






@ssemilla By using ` instead of " it runs but not working properly it prints nothing
– stack
Nov 17 '18 at 9:55














Why are you using !validation.MatchString() instead of just validation.MatchString()?
– ssemilla
Nov 17 '18 at 9:58




Why are you using !validation.MatchString() instead of just validation.MatchString()?
– ssemilla
Nov 17 '18 at 9:58












1 Answer
1






active

oldest

votes


















0














. is an invalid escape sequence. I would suggest you use backticks when defining regular expressions. e.g.



regexp.MustCompile(`^https?://.*.(jpg|gif|png)$`) // this will just check if the url ends with jpg,gif,png


If you are not using the capture groups, this is a simpler approach. However when parsing or validating URLs, use url.Parse() which provides better validation.






share|improve this answer























  • This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
    – ssemilla
    Nov 17 '18 at 10:43










  • if I used your code given regexp it was also correct?'
    – stack
    Nov 17 '18 at 11:44










  • It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
    – ssemilla
    Nov 17 '18 at 11:46










  • Ohh okay thanks for the nice answer :) @ssemilla
    – stack
    Nov 17 '18 at 12:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350013%2fhow-to-solve-the-error-of-unknown-escape-sequence-and-2-more-errors%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














. is an invalid escape sequence. I would suggest you use backticks when defining regular expressions. e.g.



regexp.MustCompile(`^https?://.*.(jpg|gif|png)$`) // this will just check if the url ends with jpg,gif,png


If you are not using the capture groups, this is a simpler approach. However when parsing or validating URLs, use url.Parse() which provides better validation.






share|improve this answer























  • This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
    – ssemilla
    Nov 17 '18 at 10:43










  • if I used your code given regexp it was also correct?'
    – stack
    Nov 17 '18 at 11:44










  • It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
    – ssemilla
    Nov 17 '18 at 11:46










  • Ohh okay thanks for the nice answer :) @ssemilla
    – stack
    Nov 17 '18 at 12:00
















0














. is an invalid escape sequence. I would suggest you use backticks when defining regular expressions. e.g.



regexp.MustCompile(`^https?://.*.(jpg|gif|png)$`) // this will just check if the url ends with jpg,gif,png


If you are not using the capture groups, this is a simpler approach. However when parsing or validating URLs, use url.Parse() which provides better validation.






share|improve this answer























  • This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
    – ssemilla
    Nov 17 '18 at 10:43










  • if I used your code given regexp it was also correct?'
    – stack
    Nov 17 '18 at 11:44










  • It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
    – ssemilla
    Nov 17 '18 at 11:46










  • Ohh okay thanks for the nice answer :) @ssemilla
    – stack
    Nov 17 '18 at 12:00














0












0








0






. is an invalid escape sequence. I would suggest you use backticks when defining regular expressions. e.g.



regexp.MustCompile(`^https?://.*.(jpg|gif|png)$`) // this will just check if the url ends with jpg,gif,png


If you are not using the capture groups, this is a simpler approach. However when parsing or validating URLs, use url.Parse() which provides better validation.






share|improve this answer














. is an invalid escape sequence. I would suggest you use backticks when defining regular expressions. e.g.



regexp.MustCompile(`^https?://.*.(jpg|gif|png)$`) // this will just check if the url ends with jpg,gif,png


If you are not using the capture groups, this is a simpler approach. However when parsing or validating URLs, use url.Parse() which provides better validation.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 10:38

























answered Nov 17 '18 at 10:23









ssemilla

3,077424




3,077424












  • This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
    – ssemilla
    Nov 17 '18 at 10:43










  • if I used your code given regexp it was also correct?'
    – stack
    Nov 17 '18 at 11:44










  • It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
    – ssemilla
    Nov 17 '18 at 11:46










  • Ohh okay thanks for the nice answer :) @ssemilla
    – stack
    Nov 17 '18 at 12:00


















  • This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
    – ssemilla
    Nov 17 '18 at 10:43










  • if I used your code given regexp it was also correct?'
    – stack
    Nov 17 '18 at 11:44










  • It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
    – ssemilla
    Nov 17 '18 at 11:46










  • Ohh okay thanks for the nice answer :) @ssemilla
    – stack
    Nov 17 '18 at 12:00
















This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
– ssemilla
Nov 17 '18 at 10:43




This might be a more proper regex for the URL: ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ which was taken from here: stackoverflow.com/questions/169625/…
– ssemilla
Nov 17 '18 at 10:43












if I used your code given regexp it was also correct?'
– stack
Nov 17 '18 at 11:44




if I used your code given regexp it was also correct?'
– stack
Nov 17 '18 at 11:44












It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
– ssemilla
Nov 17 '18 at 11:46




It won't validate invalid URL characters. I suggest you use ^https?://(?:[a-z0-9-]+.)+[a-z]{2,6}(?:/[^/#?]+)+.(?:jpg|gif|png)$ if you really need a regex.
– ssemilla
Nov 17 '18 at 11:46












Ohh okay thanks for the nice answer :) @ssemilla
– stack
Nov 17 '18 at 12:00




Ohh okay thanks for the nice answer :) @ssemilla
– stack
Nov 17 '18 at 12:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350013%2fhow-to-solve-the-error-of-unknown-escape-sequence-and-2-more-errors%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?