Fill the histogram with water Imagine a histogram. Pour an infinite amount of water on to it. Then stop. How much water does the histogram hold?

Let's say we have a histogram with columns of these heights:

1 3 2 1 4 1 3 

That would look like this:

    #
 #  # #
 ## # #
#######
1321413


If we pour an infinite amount of water on this histogram, some of those holes will fill up, and we'll end up with this:

    #
 #..#.#
 ##.#.#
#######
1321413


Apparently, this histogram can hold 5 slots of water.

Your task, should you choose to accept it, is to calculate the number of slots of water that a given histogram can hold. You may accept the input as a list, string, array, matrix, bitmap or whatever format you like. The output should be nothing but a single integer, in any format you like.

The input will only contain column heights between 1 and 1000, and the input size is between 1 and 1000 columns.

Test cases:

1 -&gt; 0
2 1 2 -&gt; 1
1 3 2 1 4 1 3 -&gt; 5
1 3 5 7 6 4 2 1 -&gt; 0
7 1 1 1 1 1 1 1 1 1 7 -&gt; 54
2 6 3 5 2 8 1 4 2 2 5 3 5 7 4 1 -&gt; 35


If you're looking for possible ways to solve this problem, here's four.

This is code golf, so the least bytes of source code wins.
Retina, 16 bytes

(?&lt;=# *) (?= *#)


Try it online! Link includes test case. Works by counting the spaces which are surrounded by #s.