When I write a regex with .
in it, it doesn't match new lines.
preg_match('/.*+?/') ...
What do I need to write, to match all possible characters, and new lines too?
By default in most regex engines, . doesn't match newline characters, so the matching stops at the end of each logical line. If you want . to match really everything, including newlines, you need to enable "dot-matches-all" mode in your regex engine of choice (for example, add re. DOTALL flag in Python, or /s in PCRE.
"\n" matches a newline character.
The dot (.) matches any character. A single character that doesn't have any other special meaning matches that character. A string enclosed in brackets [ ] matches any single character from the string. Ranges of ASCII character codes may be abbreviated as in a-z0-9.
The period (.) represents the wildcard character. Any character (except for the newline character) will be matched by a period in a regular expression; when you literally want a period in a regular expression you need to precede it with a backslash.
Add the s
modifier, e.g.
'/./s'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With