# Regex for repeat words

**URL:** <https://community.glideapps.com/t/regex-for-repeat-words/59692>\
**Category:** Ask for Help\
**Created:** [March 26, 2023, 2:19am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692 "2023-03-26T02:19:07Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 4:57am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/21 "2023-03-26T04:57:16Z")

</div>

split sentence by empty space, and find the ones with “-”

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 6:16am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/22 "2023-03-26T06:16:13Z")

</div>

can you elaborate?

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [March 26, 2023, 8:47am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/23 "2023-03-26T08:47:33Z")

</div>

I’ll suggest 2 different ideas from Uzo’s.

Use **OpenAI** :

1. Use OpenAI’s playground to determine the correct regex formula/code. It would require testing of course, you might need to experiment with various models (text, codex, …), but you might be able to guide GPT well enough that it’ll be able to do it.

2. Use OpenAI’s playground to determine a prompt that could return the ouput you want based on a user input:

Dunia Anak-anak Masa Kini. //true  
Dunia Ibu-Ibu Masa Kini. //false

… and then use the OpenAI integration, specifically the Complete Prompt feature, as a computed column within a table.

Idea 2 might be a poor idea. OpenAI’s GPT is not deterministic, so I don’t think we can trust a consistent true/false format of the output (I could be mistaken).

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 9:32am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/24 "2023-03-26T09:32:42Z")

</div>

Thank you @nathanaelb

I have tried OpenAI many times before, with no luck.  
I need to rest my brain for a moment. 😵‍💫

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 10:32am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/25 "2023-03-26T10:32:01Z")

</div>

Don’t use AI to write codes, LOL. It rarely comes up well.

Here is human-written code 😉

```auto
split = p1.split(' ');
dash = split.filter(word => word.includes("-"));
splitDash = dash[0].split('-');
if(splitDash[0].toLowerCase()==splitDash[1] .toLowerCase()){
if(splitDash[1].toLowerCase()==splitDash[1]){
return 'TRUE'
}
}
return 'FALSE'

```

 ![Screen Shot 2023-03-26 at 6.29.41 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/d/1d009ff91de07fb3a8cca81afbd05e46542b540a.jpeg)

This is for one word with a dash… for more… loop the script or repeat the column with the next array index.

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 11:34am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/26 "2023-03-26T11:34:04Z")

</div>

Thanks, Uzo, you’ve come close. Here I found the side effect, which returns true:

1. Berbagai Alasan Penerbitan Undang - Undang secara Tidak Transparan. (“-” with spaces)
2. Pritzker Prize Winning Architect, Alejandro Aravena - 2016. (“-” for non-repeating words)

It’s better if the ‘-’ sign with spaces is ignored (false or empty).

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 11:50am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/27 "2023-03-26T11:50:40Z")

</div>

I made the script acording to your specifications, you did not metion, that it can be separated… Plus i do not get the concept of what you doing, so i couldn’t predict all outcomes

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 11:56am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/28 "2023-03-26T11:56:46Z")

</div>

Yes, I know. Sometimes we also don’t know user behavior. Therefore it should be considered false because it is beyond the truth/validation requirement.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 11:58am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/29 "2023-03-26T11:58:04Z")

</div>

Now you have a base script to add more conditions, it should be easy for you… 😉

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 11:59am UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/30 "2023-03-26T11:59:40Z")

</div>

I will try to modify it. Very grateful.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 3:31pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/31 "2023-03-26T15:31:14Z")

</div>

try this:

```auto
string = p1.replace(/\s*-\s*/g, "-");
split = string.split(' ');
dash = split.filter(word => word.includes("-"));
splitDash = dash[0].split('-');
if(splitDash[0].toLowerCase()==splitDash[1] .toLowerCase()){
if(splitDash[1].toLowerCase()==splitDash[1]){
return 'yes'
}
}
return 'no'

```

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 3:39pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/32 "2023-03-26T15:39:02Z")

</div>

Nice to see you again, people who don’t give up. 😜  
I got the script as follows, maybe you can give your opinion:

```auto
const split = p1.split(' ');
const dash = split.filter(word => word.includes("-") && word.indexOf("-") !== 0 && word.indexOf("-") !== word.length - 1);
const splitDash = dash[0].split('-');

if (splitDash.length == 2 && splitDash[0].toLowerCase() === splitDash[1].toLowerCase()) {
  if (splitDash[0].toLowerCase() === splitDash[1].toLowerCase() && splitDash[1] === splitDash[1].toLowerCase()) {
    return 'true';
  }
}

return 'false';

```

This is thanks to openAI, even though it is very annoying to explain what we mean and never give up on to answer, even though the answer is the same as before. 😁

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 3:45pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/33 "2023-03-26T15:45:28Z")

</div>

no, your script will not work if you have more than 1 space:

> ```
> a -a a - a a- a
> 
> ```

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 3:47pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/34 "2023-03-26T15:47:55Z")

</div>

Yes, I think your last script is useful too. Since you ignore spaces, this means I can allow the user to write with or without spaces.

A little more if it is able to detect a lot of repeated words then this script will be perfect.  
Like the following example sentence: Dunia Anak-Anak, Bapak-bapak dan Ibu-ibu Masa Kini.

NB: There’s something I need to ask too, why doesn’t the javascript column seem to accept the new function anymore?

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 3:57pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/35 "2023-03-26T15:57:07Z")

</div>

I don’t know what you mean…

> [@Himaladin](#):
>
> why doesn’t the javascript column seem to accept the new function anymore?

What would be the output for multiple matches?

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 3:59pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/36 "2023-03-26T15:59:56Z")

</div>

Sorry, I wanted to fix the thread before your rushed answer. For example, writing in front using the function similarWord { …

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 4:00pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/37 "2023-03-26T16:00:50Z")

</div>

there is no function like that

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 4:01pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/38 "2023-03-26T16:01:42Z")

</div>

Never mind, forget it.

---

<div class="post-metadata">

**Author:** ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)\
**Post date:** [March 26, 2023, 4:20pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/39 "2023-03-26T16:20:11Z")

</div>

> [@Himaladin](#):
>
> Dunia Anak-Anak, Bapak-bapak dan Ibu-ibu Masa Kini.

Hey @Uzo, give your opinion with the following script:

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

```

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [March 26, 2023, 4:26pm UTC](https://community.glideapps.com/t/regex-for-repeat-words/59692/40 "2023-03-26T16:26:39Z")

</div>

😉

res=0

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

[Previous page](https://community.glideapps.com/t/regex-for-repeat-words/59692.md?page=1)

[Next page](https://community.glideapps.com/t/regex-for-repeat-words/59692.md?page=3)
