Regex for repeat words

Nope, not working.

It works… it will show you the number of matches.

if(p1){
var res=0;
var string = p1.replace(/\s*-\s*/g, "-");
var split = string.split(' ');
var dash = split.filter(word => word.includes("-"));
for (let i = 0; i < dash.length; i++) {
  var splitDash = dash[i].split('-');
  if(splitDash[0].toLowerCase() === splitDash[1].toLowerCase()){
    if(splitDash[1].toLowerCase() === splitDash[1]){
      res=res+1;
    }
  }
}
return res;
}

Why are you crunching the numbers, I didn’t ask for it. :wink: I’ll save it, it might come in handy someday.
Why are your script and image different but working?

How else are you going to show multiple?

if you don’t need to show count… then replace res=“TRUE”
As I said… is hard to guess what you need because I don’t know your purpose…
If you explain the flow in the beginning… you will have a code in 10 min… :wink:
it took me a long time to understand what you need… and I guess… I still don’t get it.

(I replaced the image with a matching one, I adjusted the script, to eliminate global variables, and error on empty input)

Nice, you are great. :v:

1 Like

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