String.contains
contains($matchString, $options = {}) -> boolean
Description
Check for the existence of $matchString
and return true
or false
.
If $options
is -ignoreCase
it will match both upper and lowercase versions of each character.
'abcdef'.contains('def') //= true 'abcdef'.contains('xyz') //= false 'abcdef'.contains('CDE', -ignoreCase) //= true
Regex Patterns
If you need to match a pattern within the string, you can use match
instead.
'abc 123 xyz'.match(r'\d+') //= '123' // i = ignore case '123 Abc Xyz'.match(r'(abc|def)'i) //= 'Abc'