Javascript regex

please i need someone to explain this code for me , i can’t really understand it

let repeatNum = "42 42 42";
let reRegex = /^(\d+)\s\1\s\1$/;
let result = reRegex.test(repeatNum);

ur regex expression say 0 or;more digit at the begining then space then 0 or more digit ,then space,then 0 or;more digit at the end,hope it helps

thanks, i really appreciate

sorry but what of if word like “come” is replaced with that number how will i do it with regex

u are welcome chijio*_*

oh think u u can use \w,for letters

thank bro, i really appreciate

can someone help me explain this code don’t really understand it

if(arr[i].indexOf(elem) == -1){

    newArr.push(arr[i])
  }

Which part do you not understand? Usually if im not sure what some code is doing, i google parts of the code piece by piece and find out what its doing.

that first lines of code is very hard for me to interpreat it;
if(arr[i].indexOf(elem) == -1){}

if you look up indexOf it looks at an array (arr[i]) and returns the index of the element in the parentheses (elem), or -1 if that element is not found. So if element is not found, push arr[i] to newArr.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.