Why no do-blocks for regex matching

You can employ syntax almost identical to the linked Python example’s in Julia, because Julia’s assignment operator (=) has always behaved much like Python’s new-fangled := in that it returns its right-hand side. e.g.

if (m = match(rx, str)) !== nothing
    @show m
end

(That being said, Python currently allows := in more contexts than Julia, e.g. Julia doesn’t allow assignments inside array literals.)

6 Likes