4 ms·
> did I unintentionally use some metacharacter in this part of the string which I meant to be “fixed”? When in doubt, just throw a backslash in front of it, wh
by Cyberdog 5y ago
> did I unintentionally use some metacharacter in this part of the string which I meant to be “fixed”?
When in doubt, just throw a backslash in front of it, which always means "the next character is to be interpreted literally," even in cases where it's not necessary.
(Well, not always; the backslash will invoke a special character when thrown before some letters; eg, "\t" means the tab character. But normal letters never need to be escaped; just punctuation.)
- burntsushi 5y agoFun fact: Rust's regex crate won't let you do this. If you try to escape a character that isn't a meta character, you get an error. So in cases like this, it will erase your doubt. (There is ongoing discussion about relaxing this rule for some characters, since it is so common in some cases. For example, escaping / so common that folks try to do it with the regex crate and are surprised when it returns an error. / is rarely a regex meta character, rather, it tends to denote the start and stop of regexes, e.g., in Javascript or sed.)