Multi-flags regex doesn't work in javascript

they say multi flag regex works just like this :
if we were to give both the flags i and g to the regex /a/ , we’d write /a/ig (or equivalently /a/gi , since the order doesn’t matter).
but it’s not working in my case,



function check() { const regex = /[a-z]/gi; const strArray = textInput.value.match(regex); console.log(strArray); if (strArray.join('') === strArray.reverse().join('')) { result.innerText =${textInput.value} is a palindrome; result.style.display = "block"; } else { result.innerText = ${textInput.value} is not a palindrome; result.style.display = "block"; } }

Take a closer look at the strArray value after matching, it might look a bit different than what you expect.

For the future - please share your code as a text, instead of images.

thank you for the reply but i still don’t get it

What’s the value of strArray in the first case and what’s in the second?

You can add console.log(strArray) to be able to see that in console.

1 Like

but i want it to ignore the case i flage is there… why?
are you saying the problem is in the if statement condition

It ignored, but only as far as matching the letter. /[a-z]/i or /[a-z]/gi will match both uppercase and lowercase letters. It will not change the casing in what it returns.

1 Like

thank u ,I understand now
i actually found the solution when you said the first hint but i didn’t like it

function check() {
  const regex = /[a-z]/ig;
  const strArray = textInput.value.match(regex);
  if (strArray.join('').toLowerCase() === strArray.reverse().join('').toLowerCase()) {
      result.innerText = `${textInput.value} is a palindrome`;
      result.style.display = "block";
    } else {
      result.innerText = `${textInput.value} is not a palindrome`;
      result.style.display = "block";
    }
}