Skip to main content
Participant
November 7, 2008
Question

FindGrep / ChangeGrep -- findWhat -- How to do a case-insensitive search?

  • November 7, 2008
  • 6 replies
  • 1756 views
I'm totally boggled by the syntax requirements for doing a case-insensitive search. I'm used to something akin to /fubar/i , which would match Fubar, fubar, fUbAr, etc.

Using InDesign's grep facilities, how do I do a case-insensitive search? Thanks.
This topic has been closed for replies.

6 replies

Known Participant
November 7, 2008
Hi jlevy,

re: "To the last post, then, I can simply use the GUI to build up a regexp if necessary (because the syntax does differ somewhat from traditional grep)"

Yes, build the grep expression in the Find/Change panel, then, from the ESTK, send this:

$.writeln(app.findGrepPreferences.findWhat);

...and the grep string will appear in the JavaScript Console window. You may well have to escape some characters to get it to work. To test, try copying the string out of the JavaScript Console and assigning it to a variable. Then try:

//Clear findWhat to avoid false positives:
app.findGrepPreferences.findWhat = "";
//Where myString is the grep expression:
app.findGrepPreferences.findWhat = myString;

...then go back to InDesign and look at the Find What field in the Find/Change panel. Does it match the string you entered earlier? If so, you're good to go. If not, it's probably a matter of escaping some backslashes or quotes.

re: list of operators

As far as I know, the pop-up menus in the Find/Change panel constitiute the only list--but it's not comprehensive. Quite a bit of standard JS regular expressions work there, but are not available through pop-up menus.

Thanks,

Ole
_jlevy_Author
Participant
November 7, 2008
AH, ok. I tried the (?), but at the end of my needle. Thanks! Is there a list of all operators I can find somewhere in the documentation?

To the last post, then, I can simply use the GUI to build up a regexp if necessary (because the syntax does differ somewhat from traditional grep)

Thanks!
Known Participant
November 7, 2008
Hi jlevy,

To expand somewhat on what Peter said (thanks, Peter!): the strings that you enter in findWhat and changeTo are the same as the strings you enter in the Find/Change dialog box, with the exception of characters that must be "escaped" in a JavaScript string (such as quotation marks and backslashes).

Thanks,

Ole
Peter Kahrel
Community Expert
Community Expert
November 7, 2008
As Ole said,

>app.findGrepPreferences.findWhat = "(?i)fubar";

Peter
_jlevy_Author
Participant
November 7, 2008
Righto, but my question applies to the scripting of the case-insensitive search.

in a jsx script, I have the following,

app.findGrepPreferences.findWhat = "fubar";
app.changeGrepPreferences.changeTo = "Snafu";
app.documents.item(0).changeGrep();

... in my document, I have "Fubar". My findWhat search string won't find it because of the case. How to take what I have above, in scripting, and set a case-insensitivity flag of some kind?
Known Participant
November 7, 2008
Hi jlevy,

Take a look at the pop-up menu associated with the Find What field in the Find/Change panel. At the bottom, you'll see the Modifiers submenu. On that submenu, you'll see the Case Insensitive On menu item. Choosing this enters (?i).

Thanks,

Ole