Replacing multiple occurences of character in bash

I wanted to replace multiple occurrences of underscore with single in one bash shell script. With regular expressions this is pretty simple, but by default they are not available directly in bash (using awk, sed and other tools would have obviously solved the problem). The “pure bash” solution involved turning on the regexps with shopt -s extglob:

$
$ shopt -s extglob
$ filename=Test____document__v10.pdf
$ echo ${filename//+(\_)/_}
Test_document_v10.pdf
$