Grep Find/Replace, multiple formatting applied
Learn / Forums / General InDesign Topics / Grep Find/Replace, multiple formatting applied
Tagged: find/replace
- This topic has 11 replies, 3 voices, and was last updated 7 years, 6 months ago by Kelli Fleck.
-
AuthorPosts
-
-
October 19, 2016 at 8:20 am #89146Kelli FleckMember
I am wondering if there is a way for me to replace the word “pKa” with different formatting. For example, I have throughout multiple documents the instance of:
p (regular lowercase) K (regular uppercase) a (subscripted regular lowercase)
I want to change it to:
p (regular lowercase ) K (italics uppercase) a (regular lowercase)
Is there a way to do this in Find/Replace all, perhaps with GREP? So far I have only seen a way to change for one type of formatting and not multiple.
-
October 19, 2016 at 8:52 am #89150Matt IsaacParticipant
I’m pretty sure this can only be done with two grep expressions first to change the K:
(?<=\<p)K(?=a\>)
second to change the a:(?<=\<pK)a\>
These can be combined into a single shortcut command if applied via script such as:
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(?<=\\<p)K(?=a\\>)";
app.changeGrepPreferences.fontStyle = "Italic";
app.changeGrep();app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(?<=\\<pK)a\\>";
app.changeGrepPreferences.position = Position.NORMAL;
app.changeGrep();
for information on installing and using the script see:https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post.php
-
October 19, 2016 at 9:08 am #89152Kelli FleckMember
Great! Just used those expressions and it did the job. Thank you!!
-
October 19, 2016 at 9:09 am #89153Kelli FleckMember
OH! LOVE that. I am going to create that shortcut. Thank you!
-
October 19, 2016 at 9:21 am #89156Kelli FleckMember
Trying to write one for ml to mL..I got this far:
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = “(?<=\\<m)l\\>”;
app.changeGrepPreferences.position = Position.NORMAL;
app.changeGrep();Could you help with this one?
Do you know any good sites for learning the basics in GREP?
-
October 19, 2016 at 10:04 am #89158Matt IsaacParticipant
https://creativepro.com/resources/grep
would be a good starting point for learning GREP.
The GREP for ml to mL would be a bit simpler than your kPa find:\<ml\>
change to:mL
here are the expressions broken down to hlep you to understand them:
(?<=)
:This piece of grep looks behind for anything after the ‘=’ without selecting it (eg.(?<=f)un
will select ‘un’ only if it is after ‘f’).
(?=)
does the same for looking ahead (eg.f(?=un)
, will only select ‘f’ if it is before ‘un’).
\<
and\>
looks for word beginnings and endings respectively. (eg\<fun\>
will only find ‘fun’ not ‘funny’ or ‘funds’) -
October 19, 2016 at 10:31 am #89161Matt IsaacParticipant
https://helpx.adobe.com/indesign/using/find-change.html
also has some useful tips. -
October 19, 2016 at 10:47 am #89162Kelli FleckMember
Oh great! Thank you for all the help. And thank you for the helpful explanation. I am on my way to learning some GREP!
-
October 20, 2016 at 7:21 am #89175Jay FarschmanMember
Have you guys ever used https://rubular.com to test your expressions? I’d recommend it. It’s a fast way to test your expressions.
In my last job I wrote a lot of code and sometimes figuring out the regular expressions (REGEX) was the hardest part. If you don’t use this tool, what are you guys using? Finding the right tools is important.
-
October 21, 2016 at 9:06 am #89245Kelli FleckMember
Hey I am having trouble with the script for pKa, changing the a. It is because there is a character style applied to it. Any suggestions? It makes the a normal but there was a 1.5pt baseline shift on the subscript character style. So it still has the 1.5pt baseline shift but no subscript.
Is there a way to add 0pt baseline shift to the code?
:) Thanks for any help!
-
October 21, 2016 at 10:16 am #89249Matt IsaacParticipant
Just set
app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0]
in the script just after the position line.. If the subscript was applied with a character style you will be able to remove that line as setting the character style to none will take out the subsccript anyway. -
October 21, 2016 at 10:25 am #89250Kelli FleckMember
Perfect!! Works like a charm. Thank you!!
-
-
AuthorPosts
- You must be logged in to reply to this topic.