>str= "AAC|Australia Acquisition Corp. - Ordinary Shares|S|N|D|100"
> strsplit(str,"\\|")
[[1]]
[1] "AAC"
[2] "Australia Acquisition Corp. - Ordinary Shares"
[3] "S"
[4] "N"
[5] "D"
[6] "100"
I wonder \\| is equal to | ?
maybe \\|is equal to \| ,
why can strsplit(str,"\\|") work?
Because it’s a quoted string.
In a quoted string, you can include a
"character by escaping it with a\. A\itself then also needs to be escaped to be a single literal backslash. So your quoted string means:\|.Now in a regular expression a
|is a special character that is not matched literally unless it is escaped. Regular Expressions in R also escape with a backslash, so the string literal"\\|"means the string\|which is an expression matching exactly|. Why"\\|"works is because that means matching exactly|which appears as the separator in the string you’re splitting.A more specific reference to regular expressions in R might be handy, but it, as many do, references perl regular expressions.