Regular expressions, ever versatile, will help up locate HTML tags in a string today.
Pattern matching HTML strings serves at least one crucial function in web dev: sanitizing user input. Allowing user-submitted strings opens one's application to significant vulnerability. Supposing, for example, some ne'er-do-well on the internet submitted a comment that includes <script src="[path]/stealYourData.js"></script>
. Regular expressions allow us to match HTML tags in a string, because HTML tags conform to a certain pattern:
- begin and end with brackets (<>)
- contain a string name consisting of one or more lowercase letters, like p, a, div, strong, script