String Contains Any Items in an Array (Case Insensitive)

String contains any items in an array (case insensitive)

is that what you wanted? i hope that code is compiling :)

$string = 'My nAmE is Tom.';
$array = array("name","tom");
if(0 < count(array_intersect(array_map('strtolower', explode(' ', $string)), $array)))
{
//do sth
}

How can I make Array.Contains case-insensitive on a string array?

array.Contains("str", StringComparer.OrdinalIgnoreCase);

Or depending on the specific circumstance, you might prefer:

array.Contains("str", StringComparer.CurrentCultureIgnoreCase);
array.Contains("str", StringComparer.InvariantCultureIgnoreCase);

Check if any word from a string is in an array (Case insensitive)

You can use array_uintersect, which takes a comparison function in which you can do case-insensitive comparison with strcasecmp:

$response = 'Ingredients: Whey, bEEf, EgG, NuTs';

$items = array_map('trim', array_slice(preg_split('/[:,]/', $response), 1));

$array = [ 'Beef', 'Nuts'];

$result = array_uintersect($array, $items, fn($a, $b) => strcasecmp($a, $b));

print_r($result);

javascript includes() case insensitive

You can create a RegExp from filterstrings first

var filterstrings = ['firststring','secondstring','thridstring'];
var regex = new RegExp( filterstrings.join( "|" ), "i");

then test if the passedinstring is there

var isAvailable = regex.test( passedinstring ); 

Check if string contains an element from array ignoring case (JavaScript)

Change from

chk => chk.toLowerCase().includes(chk)

to

val => val.toLowerCase().includes(chk.toLowerCase())

or

const ar = ["[Text]", "[More]", "[AnotherText]", "[Stuff]", "[Yes]"];

const isContain = (arr, chk) =>
arr.some(
(val) =>
val.toLowerCase().includes(chk.toLowerCase()) ||
chk.toLowerCase().includes(val.toLowerCase())
);


console.log(isContain(ar, "tExt"))

Check whether string contains substring (NON CASE SENSITIVE)

If you want to know whether array contains required non case sensitive string some with toLowerCase may be good solution:

const findStr = (arr, str) => arr.some(e => e.toLowerCase().search(str.toLowerCase()) !== -1)
const arr = ['Hallo', 'I am listening', 'CaLling iT', 'haLLing']
console.log(findStr(arr, 'CaLlI'))console.log(findStr(arr, 'i AM Lis'))console.log(findStr(arr, 'Ca1'))

Check if a string exists in an array case insensitively

you can use

word.lowercaseString 

to convert the string to all lowercase characters

Check if string contains a value in array

Try this.

$string = 'my domain name is website3.com';
foreach ($owned_urls as $url) {
//if (strstr($string, $url)) { // mine version
if (strpos($string, $url) !== FALSE) { // Yoshi version
echo "Match found";
return true;
}
}
echo "Not found!";
return false;

Use stristr() or stripos() if you want to check case-insensitive.

Detect if string contains any element of a string array

In additional to answer of @Sh_Khan, if you want match some word from group:

let str:String = "house near the beach"
let wordGroups:[String] = ["beach","waterfront","with a water view","near ocean","close to water"]
let worlds = wordGroups.flatMap { $0.components(separatedBy: " ")}
let match = worlds.filter { str.range(of:$0) != nil }.count != 0


Related Topics



Leave a reply



Submit