Regex return false if one condition is false

I am new with regex and I wrote something what returns a match also if one part is correct.

This is incorrect, but the expression is returns true

This is correct return true

^(((https?:\/\/[w]{3}[.]{1})+([a-z0-9]{1,})(.*-[a-z]{1,})?)[.]{1}[a-z]{2,3}\/[a-z]{1,}(.*-[a-z]{1,})?)

*Important if the url contains – there must be a letter after if there is no letter after the expression is incorrect and return false *

>Solution :

You forgot the dollar sign!

Try this

/^((https?:\/\/[w]{3}[.]{1})+([a-z0-9]{1,})(.*-[a-z]{1,})?)[.]{1}[a-z]{2,3}(\/[a-z0-9]{1,})?(.*-[a-z]{1,})?$/

Leave a Reply