MutterCorp
MutterCorpNotice · Notícias
Programação·

The m and s regex flags, explained with one example

Two JavaScript regex flags get mixed up constantly: m (multiline) and s (dotAll). They sound related, but they change completely different things. Take this text: error: disk full info: retrying error: timeout m changes what ^ and $ mean Without m, ^ matches only at the very start of the whole string and $ only at the very end. const log = "error: disk full\ninfo: retrying\nerror: timeout"; log.match(/^error: .*$/g); // null — $ can't match before the \n log.match(/^error: .*$/gm); // ["error:…

Publicado no Notice. Categoria: Programação.

Notícias sobre o mesmo assunto em outras fontes