Skip to main content
David André Erichsen
Inspiring
October 3, 2014
Answered

GREP trouble

  • October 3, 2014
  • 2 replies
  • 620 views

Hi,

I want to change lists that comes numbered like tils:

1. some text

2. some text

3. some text

to this

1) some text

2) some text

3) some text

This GREP work if i do a manual search in InDesign:   "(?<=^\d)\. |(?<=^\d\d)\."  ->  ") "

But when i put it into this script (works with other search-criteria) nothing happens:

Can someone please tell why this does'nt this work?

if (parseFloat(app.version) < 6)

doReplace();

else

app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");

function doReplace ()

{

if (parseFloat(app.version) < 6)

doReplace();

else

app.doScript(doReplace, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");

function doReplace ()

{

try {

  RemoveExcessSpacing();

} catch(err) {

        var msg = "Select textframe";

        alert(msg);

}

function RemoveExcessSpacing() {

  var story;

  var doc   = app.activeDocument;

  var sel   = doc.selection;

  var frame = sel[0];

  if (frame && frame.constructor.name === "TextFrame") {

  story = frame.parentStory;

  } else {

  throw "Ingen tekstblokk markert";

  }

app.findGrepPreferences.findWhat = "(?<=^\d)\. |(?<=^\d\d)\. ";

app.changeGrepPreferences.changeTo = ") ";

story.changeGrep();

}}}

This topic has been closed for replies.
Correct answer pixxxelschubser

,

do you really work wtih manually created numbered lists? That's not the best way.

All the same – one variant:

replace this line:

app.findGrepPreferences.findWhat = "(?<=^\d)\. |(?<=^\d\d)\. ";

with this:

app.findGrepPreferences.findWhat = /(?<=^\d)\. |(?<=^\d\d)\. /.source;

- - - - - - -

But IMHO better is:

app.findGrepPreferences.findWhat = /^(\d+)\./.source;

app.changeGrepPreferences.changeTo = "$1)";

And the best way:

automatically numbered lists – several settings possible and no Grep needed

Have fun

2 replies

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
October 4, 2014

,

do you really work wtih manually created numbered lists? That's not the best way.

All the same – one variant:

replace this line:

app.findGrepPreferences.findWhat = "(?<=^\d)\. |(?<=^\d\d)\. ";

with this:

app.findGrepPreferences.findWhat = /(?<=^\d)\. |(?<=^\d\d)\. /.source;

- - - - - - -

But IMHO better is:

app.findGrepPreferences.findWhat = /^(\d+)\./.source;

app.changeGrepPreferences.changeTo = "$1)";

And the best way:

automatically numbered lists – several settings possible and no Grep needed

Have fun

David André Erichsen
Inspiring
October 4, 2014

Thank you.

Its just for a quiz in a newspaper. The list comes in text, and I want it formatted slightly different. Now I can just run the script, and everything is OK. again, thank you!

Obi-wan Kenobi
Legend
October 4, 2014

Hi David and Pixxxel,

Take a look to:  Finding and replacing Paragraph Style of last line in a bulletted list?

A very clever script written by Kaï Rubsamen! 

At the beginning, text with "1. ", "2. ", … (manual numbering):

Simply create the 3 para styles you need (with auto-numbering as Pixxxel suggested! ):

Launch Kaï's script:

Its UI appears. Only type the Grep code you need to make the research, choose your 3 para styles, as indicated in the screenshot, and finish by "OK":

DONE! 

I like a lot this script! Thanks Kaï to have written it! 

Inspiring
October 4, 2014

change \d to \\d