![]() |
The ES9 of ECMAScript 2018 JavaScript has a modifier called s in regular expression (RegExp) that allows the period (.) character to match newline characters (\n), this improves pattern searches in multi-line strings by considering newlines as any other character. The use of the dot in multiline text was restrictive because it didn’t accommodate new lines until ES9, as used by modern browsers this makes handling of text blocks in regex operations easier through the s modifier. Syntax/regexp/s or new RegExp("regexp", "s") Example 1: The given below example matches all characters inclusive of newline characters in a multiline string.
Output Match found: world. Welcome to GeeksforGeeks Example 2: The given below example shows the difference between using s modifier and not using it.
Output Without 's' modifier: null With 's' modifier: world. Welcome to GeeksforGeeks Supported BrowsersThe RegExp
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |