-1

I confuse with condition regex in bash with match if not contain string. I use regex: ^((?!success).)*$

and test online ok

but use it in bash not ok. It not exactly

string="success"
pattern='^((?!success).)*$'

if  [[ $string =~ $pattern ]]; then
    echo "found"
else
    echo "not found"
fi

please help me. enter image description here

  • bash uses POSIX "extended" regular expression syntax, which doesn't support lookahead assertions. See ["Why does my regular expression work in X but not in Y?"](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) over on the Unix & Linux stackexchange. – Gordon Davisson May 25 '22 at 08:22

0 Answers0