GREP Replace Metacharacters
Learn / Forums / General InDesign Topics / GREP Replace Metacharacters
- This topic has 4 replies, 3 voices, and was last updated 8 years, 1 month ago by Aaron Troia.
-
AuthorPosts
-
-
February 8, 2016 at 2:55 pm #81640Aaron TroiaParticipant
I was doing a GREP search to capitalize the first letter at the beginning of multiple lines and I have no trouble finding the lower case but I cant seem to us \\u in replace to capitalize my search group for example:
Find:
^\l
Replace:\U$0\E
This works in Sublime Text to capitalize, but cannot seem to figure out a way to do it in InDesign just with GREP, is there a way to do it? Are there metacharacters out there that will work in InDesign in a similar way? I understand Sublime and InDesign are using different GREP engines but it would be handy to use the uppercase/lowercase metacharacters in both find and replace, not just in find.
-
February 9, 2016 at 8:00 am #81678Peter KahrelParticipant
A. — This does doesn’t work in InDesign. Several feature requests have been submitted without much effect (please add your own).
One workaround, if the font you use has All Caps, is to look for ^\l and apply allcaps.
The other workaround is a script, which can be very simple in principle:
app.findGrepPreferences = null; app.findGrepPreferences.findWhat = '^\\l'; found = app.selection[0].findGrep(); for (i = 0; i < found.length; i++) { found[i].contents = found[i].contents.toUpperCase(); }
This targets the current selection. To target the document, replace app.selection[0] with app.activeDocument in line 3.
-
February 17, 2016 at 1:47 pm #82092Aaron TroiaParticipant
Peter,
Thank you for your response, I dont know why I didn’t think to use ^\l with allcaps, it would’ve worked just as easily to do that as what I was trying to do (I apparently was not thinking outside the GREP box). Also thank you for that workaround script, that will come in handy next time.
Aaron
-
-
February 9, 2016 at 9:03 am #81684David BlatnerKeymaster
Yes, this has been a source of frustration and many workarounds for years, including:
https://creativepro.com/using-grep-to-make-a-character-lowercase.php
https://creativepro.com/convert-text-to-lowercase-with-grep-utility.php
https://creativepro.com/grep-solution-to-flawed-title-case-feature.php
https://creativepro.com/5-cool-things-you-can-do-with-grep-styles.php-
February 17, 2016 at 1:51 pm #82093Aaron TroiaParticipant
David,
Thank you for those link, this is definitely something I need to read up on, I can’t believe I didn’t realized that InDesign didn’t do this until now.
Aaron
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.