This may sound like a silly question but in D (using std.regex) how do you match a literal dot in a string?
Using this code i’m checking for the file extension .bmp so i perform a simple regex match on it. If i try and escape the dot like this i get an error.
Regex!char Pattern = regex("\.bmp$", "i");
if (match(FileName, Pattern).empty)
{
FileName ~= ".bmp";
}
Error: Undefined escape sequence \.
Even in the documentation it doesn’t mention matching dots.
Any ideas?
I guess you need to double escape it (You want
\.in the regex). In your current code, you are single escaping it, so D tries to interpret it as something for itself, not for regex. Double escaping tells D that you want a literal\in the string.So in the end, it should look like
"\\.bmp$".