Skip to main content
Known Participant
May 11, 2021
Answered

remove spaces between words

  • May 11, 2021
  • 1 reply
  • 572 views

hello everyone, I have a file with 200 pages and I need to remove all the spaces between the number and the "mL". this is the script Im using, but its not working. I need your brilliant minds again... thank you in advance.

 

try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"\d\s\mL|\d\s\ml"});
app.changeGrepPreferences.properties = ({changeTo:"(/\s/g, '')"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findChangeGrepOptions.properties = options;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.scriptPreferences.version = scriptVersion;
This topic has been closed for replies.
Correct answer brian_p_dts

1. You have to escape backslashes when scripting Find/Replace

2. You need to call changeGrep() on a valid object (below I'm doing it on the active document)

3. Your change to would not have replaced with your finds and had incorrect syntax. Review Erica Gamet's GREP cheat sheet. This could be done without script using regular Find/Replace Grep option in InDesign. 

 

try {
    app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
    app.findGrepPreferences.properties = ({findWhat:"(\\d)(\\s)(m(l|L))"});
    app.changeGrepPreferences.properties = ({changeTo:"$1$3"});
    app.activeDocument.changeGrep();
} catch (e) {
    alert(e + ' at line ' + e.line)
} finally {
    app.findChangeGrepOptions = app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
}

 

 

 

1 reply

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
May 11, 2021

1. You have to escape backslashes when scripting Find/Replace

2. You need to call changeGrep() on a valid object (below I'm doing it on the active document)

3. Your change to would not have replaced with your finds and had incorrect syntax. Review Erica Gamet's GREP cheat sheet. This could be done without script using regular Find/Replace Grep option in InDesign. 

 

try {
    app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
    app.findGrepPreferences.properties = ({findWhat:"(\\d)(\\s)(m(l|L))"});
    app.changeGrepPreferences.properties = ({changeTo:"$1$3"});
    app.activeDocument.changeGrep();
} catch (e) {
    alert(e + ' at line ' + e.line)
} finally {
    app.findChangeGrepOptions = app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
}

 

 

 

Known Participant
May 11, 2021

Thank you so much! This is perfect