JavaScript, Intro to Regular Expressions

Photo by Markus Winkler on Unsplash

What is a regular expression?

var isPalindrome = function(s) {
//replace everything in s that is not a letter/number with an empty string/negative space
s = s.replace(/[^a-z0-9]/gi,"")
let left = 0
let right = s.length -1
while (left < right){
if (s[left].toLowerCase() !== s[right].toLowerCase()) return false
return true

In the code above:

how does it work?

s = s.replace(/[^a-z0-9]/gi,"")


A Software Engineer with a background in Education Technology and Dance. Recent grad form FlatIron Bootcamp, and passion for the arts and working with databases