The regex on page 48 is hard to read:
~r/(^https:\/\/|\/images\/).+(\.png|\.jpg)$/
It can be improved by changing the delimiters which means that you don’t have to escape all the forward slashes. Like so:
~r"(^https://|/images/).+(\.png|\.jpg)$"
The regex on page 48 is hard to read:
~r/(^https:\/\/|\/images\/).+(\.png|\.jpg)$/
It can be improved by changing the delimiters which means that you don’t have to escape all the forward slashes. Like so:
~r"(^https://|/images/).+(\.png|\.jpg)$"
Oh that’s a great idea! Thank you, we’ll do that
I don’t think that’s quite right. Going through the book today, testing the validations, the above solution doesn’t handle /images quite right. It also results in a warning on elixir 1.18/otp27.
I suggest
~S{(^https://|^/images/).+(\.png|\.jpg)$}
Note the additional ^ anchor on /images, and syntax as suggested by the warning.
Great book so far though!
From what I’ve heard the warning only appears on OTP 28, but I haven’t even managed to get the app to compile using it due to dependencies that don’t support it it’s definitely on my list of things to fix before the book goes into print.
And a good point about the extra ^
, I hadn’t realized that was missing and will fix, thank you Or even move it outside the
()
for a bit of clarity!
fwiw, I’m on otp27
Erlang/OTP 27 [erts-15.2.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.18.4 (compiled with Erlang/OTP 27)