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.
1 Correct answer
… 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
...
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
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! …" )
}
Copy link to clipboard
Copied
Jedi, mercie for this superb script. Please, help us in two points.
First, this warning message:
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
Copy link to clipboard
Copied
No error for me!
(^/)
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
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
Copy link to clipboard
Copied
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.

