The problem of "\" escaping in regular expressions
Use regular in MySQL, if you encounter to match carriage return, write this: \\n
The book says because, MySQL is explaining a \, the regular expression is explaining a \.
So I think of PHP in the same way, about \ n problem. Then I did a test:
PHP Code
Preg_match ("/\w{3}\\n\w{3}/", "aaa\naaa", $match); Var_dump ($match);
This can be the correct result, I can understand: a "\" let PHP explain, the other "\" is explained by the regular.
Then I changed the regular expression to: "/\w{3}\n\w{3}/"
This also came to the right result ~ ~ ~ I don't understand it.
Why in PHP, with a "\" can it? If according to the book, then this "\" is not interpreted by PHP? What about the regular one, no explanation?
------Solution--------------------
The regular inside is already matching the results you need. This is the Convention's symbol.
------Solution--------------------
\ n in double quotes, don't parse to wrap.
both \\n and \ n can match line breaks.
------Solution--------------------
discuss
It's wrong!
Is this:
That's like this string: $a = "AAA\\NAAA";
Must use "/\w{3}\\\\n\w{3}/" to match, this is why?
------Solution--------------------
\ n is a byte, the PRG needs to be such a byte, but it also thinks \ nthe two characters is a newline character, so the following are correct.
' \ n ' "\ n". "\\n"
------Solution--------------------
You understand the basics correctly. \ \ will be interpreted as ' \ ' by PHP, but \w PHP is still interpreted as \w
For control characters, if double quotation marks are used, \ n is interpreted by PHP as a newline, and the single quotation mark is still the character ' \ n ' in the regular expression, whether it is a newline or ' \ n ' can be matched to a newline character.