Copy link to clipboard
Copied
Hi all,
Consider a paragraph with multi lines, in between there is two lines seems empty. Now i have to break the paragraph based on the empty lines or carriage returns using GREP. Thanks for any help.
Regards,
Sasi
Hi Sasi,
Try the following, it will alert all the values that match, which you can then write to a text file or use as needed. Change the prompt word to anything else if needed, mind that the [ and ] would need to be escaped as done below. The a.contents is the text content of one block of match
...app.findGrepPreferences.findWhat = "\\[Small\\]\\r(.*[\\r\\n])+?(?=\\r\\r)";
var match = app.activeDocument.findGrep();
// Clear the find/change preferences after the search
app.findGrepPref
Copy link to clipboard
Copied
Use the following code to find the soft return and hard return i.e. paragraph break character. Then you can replace these characters with whatever you want to do, i am not all clear on what you need to do.
app.findGrepPreferences.findWhat = "\n|\r";
var match = app.activeDocument.findGrep();
// Clear the find/change preferences after the search
app.findGrepPreferences = NothingEnum.NOTHING;
The match would be an array of characters that are either \n or \r in the whole document.
-Manan
Copy link to clipboard
Copied
if youre wanting to consolidate those empty lines, then do the following
- doc.findGrepPreferences.findWhat = "[\v]+";
- doc.findGrepPreferences.changeTo = "\r";
- doc.findGrep();
then you can string.slice it using \r, or \r\r if you want to skip the prev step
Copy link to clipboard
Copied
Manan Joshi, Spicy dog -- Y'all forgot to escape your backslashes: "\\n|\\r" not "\n|\r" and "[\\v]+" not "[\v]+"
By the way, classes are more efficient than alternatives: [\n\r] works better than \n|\r
And there's no need for single-item classes: \v+ works just as well as [\v]+ (don't know if there is any difference in efficiency/speed).
P.
Copy link to clipboard
Copied
Ahh, Peter Kahrel that's where accustomed and experienced eyes come into picture. I just coded the idea without testing(picked it up from the Find/Change UI), i know this is never an excuse especially when its being told to someone in need of help. I hope i won't forget it henceforth, and regarding the efficiency thing that you mentioned, i will keep a note of that as well. Thanks for sharing your knowledge.
Copy link to clipboard
Copied
Thank you all for your replies.
Now the requirement is if the user types small in prompt, have to get all contents after the word and before the double break lines and export to a text file.I tried with regex but that did not worked.Thanks for any help.
Regards,
Sasi
Copy link to clipboard
Copied
Hi Sasi,
Try the following, it will alert all the values that match, which you can then write to a text file or use as needed. Change the prompt word to anything else if needed, mind that the [ and ] would need to be escaped as done below. The a.contents is the text content of one block of match
app.findGrepPreferences.findWhat = "\\[Small\\]\\r(.*[\\r\\n])+?(?=\\r\\r)";
var match = app.activeDocument.findGrep();
// Clear the find/change preferences after the search
app.findGrepPreferences = NothingEnum.NOTHING;
while(a = match.pop())
alert(a.contents)
-Manan
Copy link to clipboard
Copied
Thanks Mr.Manan. That works fine.
Regards,
Sasi
Copy link to clipboard
Copied
Mr.Manan Could you help me to find the above one?
Regards,
Sasi
Copy link to clipboard
Copied
Try the following
\[Small\]\n([^0-9]*\n)*\d+\n[^0-9\r]*\r
You have mentioned that all of this is part of a paragraph, i am not sure if you meant it but the regex i gave makes this assumption and each line is seperated by a soft enter i.e. shift enter with only the last line terminating in a hard enter. See the screenshot of my sample document
-Manan
Copy link to clipboard
Copied
Hi all,
Could you help me to find one more grep? That is, If the user types in prompt like small or large and another prompt types some number if both are in the are in the same paragraph alert to user. I tried the following grep. But that did not work perfectly.
(?i)\[small\]\r(.*[\r\n])+?(?=1234)(.*)+?(.*[\r\n])+?(?=\r\r)
Regards,
Sasi
Copy link to clipboard
Copied
I'm taking a wild stab on this.....
find
.*?: *([^\v]+)\v*.*?: *([^\v])
replace
[$]\rFOO\rBAR\r$2\rbiz\rbaz
Find more inspiration, events, and resources on the new Adobe Community
Explore Now