Regular expression for validating domain name
Additional logic is required to prevent something like passing as a valid domain name or to confirm that the domain is actually hosted somewhere—but I’ll leave that as an exercise for the reader.
I’ve had to retort to a very simple regex which just checks for an @ sign, something before it, at least one dot after it and at least 2 letters in the last suffix.
In this article, I have compiled 15 extremely useful regular expressions that any web developer should have in his toolkit.
For many beginners, regular expressions seems to be hard to learn and use. Before we dive deep inside regexp with useful and reusable codes, let’s quickly see the basics: $text = "Sample sentence from Komunitas Web, regex has become popular in web programming. According to wikipedia, Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor"; $text = preg_replace("/b(regex)b/i", '» Source This simple function takes two arguments: The first is the tag you’d like to match, and the second is the variable containing the XML or HTML.
Back to top You can specify options that control how the regular expression engine interprets a regular expression pattern.
The regexes in these recipes are all pretty straightforward, but hopefully this gives an example of the depth you can expect from the book. Both are followed by a question mark, which makes them optional.
For more than 100 detailed regular expression recipes that include equal coverage for eight programming languages (C#, Java, Java Script, Perl, PHP, Python, Ruby, and VB. We’ll explain more about the question mark after discussing the other types of tokens in this regular expression.
In the near future this will be likely moved to https://github.com/regexps.
I dug through lots of google matches but I can't find a correct, working regular expression to validate domain\username.