4.8.3.2 m//g Works With Multi-Line Strings or Paragraphs
4.8.3.2 m//g Works With Multi-Line Strings or Paragraphs
So far, when we have done pattern matching, we have done so over a line of text or a string that does not contain the \n character or contains \n at the very end. However, it is possible that a string has multiple lines. That is, it has one or more embedded \n characters. An example of such a string is given below.
$friends = "Tommy\tWashington\nChad\tSanFrancisco\nJeffP";
$friends .= "\tBoulder\nJeffC\tColoradoSprings\n";
The string $friends has several embedded newline characters. As a result, if printed, it comes out as several lines on the terminal or on paper. Such a string can either be typed the way we have just done or can be read from a file although we have not yet seen how we can read multiple lines or a paragraph from a file in one read operation.
