A regular expression to match all text content between the opening and closing HTML tags. Supports both single lines and multiple lines.
Don’t forget to replace the HTML tag name (
div in this example) according to your actual needs before you start using this regular expression.
It matches any string of characters, including alphanumeric characters, punctuation, and special symbols, as well as spaces and line breaks, that are contained within a
</div> HTML tag pair.
The positive lookbehind assertion
(?<=(<div>)) ensures that the pattern is preceded by the
<div> tag, while the positive lookahead assertion
(?=(</div>)) ensures that the pattern is followed by the
+? quantifier matches one or more characters in a non-greedy manner, meaning it will match the shortest possible string that satisfies the pattern.
g flag performs a global search for all matches within a string.
Note that you might find the Regex listed above only matches content between HTML tags. To include the wrapping tags, use this Regex instead: