Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Browser.text.include? to be case insensitive?

It's as simple as that:

How can I get Browser.text.include?, or Ruby in general, to be case insensitive for that specified command?

like image 385
Benjamin Avatar asked Jul 28 '11 15:07

Benjamin


People also ask

How do you ignore case-sensitive in HTML?

Comparing strings in a case insensitive manner means to compare them without taking care of the uppercase and lowercase letters. To perform this operation the most preferred method is to use either toUpperCase() or toLowerCase() function. toUpperCase() function: The str.

How do I make JavaScript not case-sensitive?

The most basic way to do case insensitive string comparison in JavaScript is using either the toLowerCase() or toUpperCase() method to make sure both strings are either all lowercase or all uppercase.

Is contains case-sensitive in JavaScript?

The return value is a Boolean value. A Boolean value can either be true or false depending on whether the substring is present or not within the string. Something to keep in mind is that the includes() method is case-sensitive.

How do you make a string case insensitive in Python?

Using the casefold() method is the strongest and the most aggressive approach to string comparison in Python. It's similar to lower() , but it removes all case distinctions in strings. This is a more efficient way to make case-insensitive comparisons in Python.


2 Answers

One of the easiest ways is to downcase or upcase the text that you're reading:

Browser.text.downcase.include?

Then, you need to make sure that your desired text is supplied in all lowercase.

like image 154
adam reed Avatar answered Oct 04 '22 04:10

adam reed


You can use String#match with a regular expression. e.g.:

("CaseSensitive".match /SENSITIVE/i) != nil

That will return true if there is a case-insensitive match, false otherwise. So for the above example, it returns true, as 'SENSITIVE' is found within 'CaseSensitive'.

For your example:

(Browser.text.match /yourString/i ) != nil
like image 45
Pete Houghton Avatar answered Oct 04 '22 03:10

Pete Houghton