How do I negate a test with regular expressions in a bash script ?

How do I negate a test with regular expressions in a bash script ?

Asked on December 28, 2018 in Regex.
Add Comment


  • 2 Answer(s)

    To negate a test with regular expressions in a bash script:

    Leave a space between the ! and the [[ like if ! [[.

    Answered on December 28, 2018.
    Add Comment

    To  insert the ! for the regex negation within the [[ ]] use this:

    if [[ ! ${STR} =~ YOUR_REGEX ]]; then
    
    
    Answered on December 28, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.