Copy link to clipboard
Copied
hello
I have this script that changes the numbers format from european to UK/US (for example 1.000 to 1,000) and doesn’t apply to the numbers preceded by any letter.
at the moment it partially works fine, changing only those numbers preceded by letters without the space between them. for example: machine model TSK4.500 won’t be changed into TSK4,500 and that’s ok.
I need it to recognize and not change also those numbers preceded by letters with a space:
TSK 4.500 must not be switched.
So in few words, I need this script to work only with numbers avoiding those that might be part of a name etc.
can someone please help me?
thank you very much![]()
Cinzia
try {main ()}
catch (_){alert ("Can't run.")}
function main (){
function FindItems (){
if (app.selection.length == 0) {return app.activeDocument.findGrep();}
if (app.selection[0].hasOwnProperty ("baseline")) {return app.selection[0].findGrep();}
if (app.selection[0] instanceof TextFrame) {return app.selection[0].parentStory.findGrep();}
exit ();
} // FindItems
// BEGIN main
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\d+[,.\\d]+\\d+";
//app.findGrepPreferences.findWhat = "[?\\l\\u]+\\d+[,.\\d]";
//app.findGrepPreferences.findWhat = "[![\\l\\u]]+\\d+[,.\\d]";
//app.findGrepPreferences.findWhat = "\\d+[,.\\d]";
var Found = FindItems ();
var Temp;
for (var i = Found.length-1; i >= 0; i--)
{
Temp = Found.contents.replace (/,/g, "#");
Temp = Temp.replace (/\./g, ",");
Found.contents = Temp.replace (/#/g, ".");
//alert(Temp);
}
app.findGrepPreferences.findWhat = "[\\l\\u]+\\d+[,.\\d]";
//app.findGrepPreferences.findWhat = "\\d+[,.\\d]";
var Found = FindItems ();
var Temp;
for (var i = Found.length-1; i >= 0; i--)
{
Temp = Found.contents.replace (/,/g, "#");
Temp = Temp.replace (/\./g, ",");
Found.contents = Temp.replace (/#/g, ".");
//alert(Temp);
}
Hi Cinzia,
As I told you in private, I think this grep code is better. Only this line to change:
app.findGrepPreferences.findWhat = /^-*[\d,.]+\d/.source;
Copy link to clipboard
Copied
Hi Obi,
Can you help me out, I have a big file with a loto of numbers for example 1 000 000 or 1000 or 1 000, were differente people writing the document what I want if to make a grep that find all these kind of formating and change the space or the non space to a dot, to get this result 1.000.000 or 1.000 or 1.000. Basically I want to format them to the European version of number formating, where the is dots between the thousands separator. Can you please help me out. Much appreciated.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more