• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
7

Grep matching consecutive letters in a list of words

Engaged ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

 

across

act

action

active

activist

actor

actress

altricial

altruism
altitude

I need help to know if building this grep is possible. The idea is to identify those words with the 4 (may be 5 or 6) first common letters within an alphabetical list.

I tried something like
       [a-z]{4,}|[A-Z]{4,}|\d{4,}

However, it is  almost absurd and I find it very complex to achieve.

Thanks.

 

TOPICS
How to , Scripting

Views

274

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Dec 11, 2023 Dec 11, 2023

… Sure!  😉

 

(^/)  The Jedi

 

/*
    _FRIdNGE-0745_BeginningOfPara.jsx
    Script written by FRIdNGE, Michel Allio [11/12/2023]
*/

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Beginning Of Para! …");

function main()     
    {
        
        // Name of your Char Style
        var myCharStyle = "red";

        // Place the cursor inside your Story
        var myStory = app.selection[0].parentStory;

        app.findGrepPreferences = app.changeGrepPrefere
...

Votes

Translate

Translate
Community Expert ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

Hi @palala fog how do you intend to "identify" those characters? A character style?

 

There are some folk on this forum who are incredible with Grep, so they may have Grep style solution, but my gut tells me that for this case a script might be a good way to go.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

… Sure!  😉

 

(^/)  The Jedi

 

/*
    _FRIdNGE-0745_BeginningOfPara.jsx
    Script written by FRIdNGE, Michel Allio [11/12/2023]
*/

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Beginning Of Para! …");

function main()     
    {
        
        // Name of your Char Style
        var myCharStyle = "red";

        // Place the cursor inside your Story
        var myStory = app.selection[0].parentStory;

        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = "(^.{4,})(?=.*\\r\\1)";
        myFound1 = myStory.findGrep();
        for ( var i = 0; i < myFound1.length; i++ ) {
            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.findWhat = "^" + myFound1[i].contents;
            myFound2 = myStory.findGrep();
            for ( var j = 0; j < myFound2.length; j++ ) if ( myFound2[j].characters[0].appliedCharacterStyle.name != myCharStyle ) myFound2[j].appliedCharacterStyle = myCharStyle;
        }
        app.findGrepPreferences = app.changeGrepPreferences = null;

        alert( "Done! …" )

    }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

Jedi, mercie for this superb script. Please, help us in two points.
First, this warning message:

Screenshot 2023-12-11 at 8.55.31 AM.png





Our idea is also to work in Spanish where the point is more interesting. Sabia is an adjective (Wise) and at the same time sabía is the past tense of a verb. Canto is a song and the first person for the verb cantar.


We would like to know if it is feasible to include these words (with accents).

Thanks!

Palala

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

No error for me!

 

(^/)

 

Capture d’écran 2023-12-11 à 15.10.33.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

This Grep expression matches consecutive words with the first 4-6 letters in common:

^([\u\l]{4,6}).+\r(\1.+\r)+

To clarify:

^ stands for beginning of paragraph;

(

   [\u\l] stands for upper- or lower-case letter; 

   {4,6} restricts the match to between 4 and 6 letters;

.+\r To the end of paragraph

(

   \1 must match the content of the previous ( )

   then to the end of the paragraph

)

+ more than once

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

Yes, fine. It is working.
Very nice replies.

And if It is possible to insert the accented vowels (áéíóú)?
May be in another grep and later we can mix the outputs.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

LATEST

Jedi, yes. The script was perfect. I copied it again. Thanks.

Mr Kahrel, your grep extended the search for 6 letters. I will use it in Jedi's script. Thanks for the aclaration. Both greps are fine.

Screenshot 2023-12-11 at 9.33.24 AM.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines