Regular Expressions ("regex" or "regexp") are a common way for web developers to use JavaScript to find specific patterns of characters -- letters, numbers, punctuation, special characters, and even whitespace such as spaces, tabs, and new lines. In this tutorial we will look at one such regex that will find an IPv4 address in a string in JavaScript.
When sifting through access and error logs, it's often useful to find the IP address in a string. Other times, you will want the user to enter this information into a form. You may also want to scrape a webpage to find any IP addresses contained within.
IPv4 address are four sets of numbers ranging from 0-255 separated by a period ("."). Any or all of the four numbers can be zero. They can have leading zeros followed by other numbers ("012" or even "000"). In this tutorial I also want to be able to pluck an IP address out of a larger body of text, such as an entry in an error log or the HTML of a webpage.