I want to test that a string contains the word ok
.
What I initially tried to do was write this regex:
ok[^a-z]
This means the next thing after my desired ok
can be some whitespace or punctuation, but not an alphanumeric character, and would correctly distinguish between just ok
and okay
, catching only the ok
.
However, the problem happens if my entire input string ends right after the ok
. The [^a-z]
mandates that another character be present to be satisfied. I don't know how to write a condition that says no more characters is also acceptable.
Desired results:
ok
- satisfied...ok...
- satisfiedok hello world
- satisfiedhello world ok
- satisfiedokay
- not satisfiedo k
- not satisfied
This is to be used in a Bash script, which according to this page, uses the ERE regex dialect.
Intended usage example:
if [[ "$@" =~ ok[^a-z] ]]; then
echo "Argument contains an \"ok\""
fi