I’m absolutely new to regex. I have watched a couple of YT videos about it, still I feel confused whenever I come across different types of regex codes - it simply makes my head spins. I need some help interpreting them.
Let’s take some examples: I want to check if a string of my JS code is an isogram. I’ve found the following lines of regex codes on Google search.
function isIsogram(word){
return !/(.).*\1|\d/i.test(word)
}
My interpretation of this code is as follows: .*
will parse any char/integer that follows it. \d
is so-called global regex, so it can be omitted. I am confused with the i.test
at the end - like I see it literally, does it test if the string variable “word” matches the regex part !/(.).*\1|\d
?
In a similar fashion, I am confused with the following regex too. It functions exactly the same like the code above (it checks if the string “word” variable is an isogram or not).
function isIsogram(str){
return !str.match(/([a-z]).*\1/i);
}
This one is much simpler than the first isogram code, but the /i
at the very end confuses me. Is it an “i” count in the for-loop examples or it’s entirely something different?