const str = "apple orange banana orange Banana";

/* Searches for a match between a regular expression and the string,
   returning the index (integer) of the first match. */
const searchPattern = /orange/;
const firstResult = str.search(searchPattern);
console.log(firstResult); // Output: 6

/* Case-sensitive.
   Example: "banana" and "Banana" are treated as different strings. */
const upperCaseBanana = /Banana/;
const banana = str.search(upperCaseBanana);
console.log(banana); // Output: 27

/* Returns -1 if no match is found. */
const hasNoSearchPattern = /mango/;
const notFoundResult = str.search(hasNoSearchPattern);
console.log(notFoundResult); // Output: -1
str.search(regexp)
const str = "Hello, World!";
const result = str.search();

console.log(result); // Output: 0
const str = "Hello, World!";
const result = str.search("");

console.log(result); // Output: 0
const str = "Hello, World!";
const result = str.search(" ");

console.log(result); // Output: 6
const str = "apple orange orange orange";
const pattern = /orange/;

const result = str.search(pattern);
console.log(result); // Output: 6
const str = "apple orange orange orange";
const pattern = /orange/g;

const result = str.search(pattern);
console.log(result); // Output: 6
const str = "Hi, World!";
const pattern = /Hello/;
const result = str.search(pattern);

console.log(result); // Output: -1
const email = "example@example.com";

if (
    email &&
    email.trim() &&
    email.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/) !== -1
) {
    console.log("The email address is valid.");
} else {
    console.log("The email address is not valid.");
}
// Output: "The email address is valid."