On Thu, Mar 05, 2015 at 02:26:48PM +0000, Jason Vas Dias wrote: > 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.]+)' > >From a quick glance, it does seem like a parsing bug, it should not break with a syntax error.
Though, you can work-around this issue by doing the recommended approach to regex matching: storing the regex in a variable. | dualbus@dualbus ~ % bash bug | + s='some text: 1.2.3' | + r='^some text:[ ]+([0-9.]+)' | + [[ some text: 1.2.3 =~ ^some text:[ ]+([0-9.]+) ]] | + echo 1.2.3 | 1.2.3 | | dualbus@dualbus ~ % cat bug | #!/bin/bash | ( set -x ; s="some text: 1.2.3"; | r=$'^some text:[ \t]+([0-9.]+)' | if [[ "$s" =~ $r ]]; then | echo "${BASH_REMATCH[1]}"; | fi | ) See http://mywiki.wooledge.org/BashGuide/Patterns#Regular_Expressions-1 and http://tiswww.case.edu/php/chet/bash/FAQ (E14).