2015-03-05 14:26:48 +0000, Jason Vas Dias: > Good day list, Chet - > > I think this is a bug: > ( set -x ; tab=$'\011'; s="some text: 1.2.3"; > if [[ "$s" =~ ^some text:[\ $tab]+([0-9.]+) ]]; then > echo "${BASH_REMATCH[1]}"; > fi > ) > -bash: syntax error in conditional expression > -bash: syntax error near `$tab]+([0-9.]+)' [...]
You forgot to quote the first space. Should be if [[ "$s" =~ ^some\ text:[\ $tab]+([0-9.]+) ]]; then I'd use [[:blank:]] to match blanks though. bash also supports \s, but that's more for [[:space:]] (so includes vertical spacing like CR, LF), and you need to use an intermediary variable: r='^some text:\s+([0-9.]+)' [[ $s =~ $r ]] or use shopt -s compat31 [[ $s =~ '^some text:\s+([0-9.]+)' ]] or use zsh in bash-3.2, the behaviour was changed (broken IMO) to match ksh93's. -- Stephane