I expect the code below to echo \"yes\", but it does not. For some reason it won\'t match the single quote. Why?
str=\"{templateUrl: \'}\" regexp=\"templateU
This should work:
#!/bin/bash str="{templateUrl: '}" regexp="templateUrl:[[:space:]]*'" if [[ $str =~ $regexp ]]; then echo "yes" else echo "no" fi
If you want to match zero or more whitespaces the * needs to added after [[:space:]].
*
[[:space:]]