Answers for "check if str contains a string"

4

find a string contain in another string

#!/bin/bash

STR='GNU/Linux is an operating system'
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]; then
  echo "It's there."
fi
Posted by: Guest on June-29-2020
0

check if a string contains a word

//By far the most accurate: VIA https://stackoverflow.com/a/25633879/7596555
function containsWord($str, $word)
{
    return !!preg_match('#\b' . preg_quote($word, '#') . '\b#i', $str);
}
Posted by: Guest on November-25-2021

Code answers related to "check if str contains a string"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language