Copy link to clipboard
Copied
Hi all,
I am trying to replace 2 specific spaces on either side of a 7 digit number with TAB spaces, mostly so I can apply my paragraph style to it. I am trying to also get it to apply only to the selected text frame.
app.findGrepPreferences.findWhat = "(?<=\d{7})\s"; //Spaces on either side of the 7 digit number
app.changeGrepPreferences.changeTo = "\t"; //replace with tabs instead of spaces
app.selection[0].paragraphs[0].changeGrep();
At this stage im not sure if it's the Javascript or the GREP that's not functioning as i want. It could be both.
Any guidance would be amazing!
Try this:
app.findGrepPreferences.findWhat = "\\s(\\d{7})\\s"; //Spaces on either side of the 7 digit number
app.changeGrepPreferences.changeTo = "\t$1\t"; //replace with tabs instead of spaces
app.selection[0].parentStory.changeGrep();
- You need to escape backslashes when you use them is strings (\\s, not \s)
- To target a textframe's contents, select it and do app.selection[0].parentStory.
P.
Copy link to clipboard
Copied
Try this:
app.findGrepPreferences.findWhat = "\\s(\\d{7})\\s"; //Spaces on either side of the 7 digit number
app.changeGrepPreferences.changeTo = "\t$1\t"; //replace with tabs instead of spaces
app.selection[0].parentStory.changeGrep();
- You need to escape backslashes when you use them is strings (\\s, not \s)
- To target a textframe's contents, select it and do app.selection[0].parentStory.
P.
Copy link to clipboard
Copied
Thank you so much Peter, it works perfectly! Lesson learned.