Home > Article > Web Front-end > How to Capture Multiline Text Within HTML Tags using JavaScript Regex?
In this scenario, you aim to retrieve the text within an HTML
Your provided pattern is:
/<div>
But it's failing to capture multiline text properly.
The issue lies in the default behavior of the dot (.) metacharacter in JavaScript. By default, . does not match newlines. To resolve this, you can use the /s (dotAll) modifier, which enables . to match newlines as well.
However, JavaScript did not support the /s modifier in older versions. Instead, you can use the following workaround:
/<div>
where:
As of ES2018, JavaScript introduced the /s (dotAll) flag. You can now use this flag directly, simplifying the pattern to:
/<div>
The above is the detailed content of How to Capture Multiline Text Within HTML Tags using JavaScript Regex?. For more information, please follow other related articles on the PHP Chinese website!