GREP Search to apply superscript

Hi there,
I'm a longtime InDesign user but I'm pretty new to GREP.
Currently I'm working on a French document, but this could easily apply to English documents as well.
I'm trying to use GREP to identify and apply superscript to letters that come after numerals indicating their position (i.e., 1st, 2nd, 3rd, etc.)
The code that I've written that I "hoped" would do this is:
(?<=\s\d+)[\l\u]+(?=\s)
What I hoped this query would do is:
1 - positive look behind for a white space followed by one or more numbers (?<=\s\d+)
2 - find any one or more letter characters [\l\u]+
3 - positive look ahead for a white space
A sample bit of text that I'm trying this on includes the following text:
...dans le cadre du 40e anniversaire...
My hope was that this would select the "e" which I could then apply superscript to. I can get parts of the code to work individually but I can't get the full query to work.
If anyone can point me in the right direction to get this working I would really appreciate it.
Thanks in advance!
Troy

Remind me again, what letters get superscripted after a number in French?
You can use something like this:
((?<=\b\d)|(?<=\b\d\d))e\b
which will pick up "4e" and "40e" -- add more digits in the first OR group, more (single) characters can be added in a character set [like this] instead of just 'e'.
WhatTheGrep's breakdown:
(  Begin Group #1
          (?<=  Lookbehind Group
                    \b  Word boundary
                    \d  Any digit (0..9)
          )  End Lookbehind Group
          |  Match previous part OR next part inside Group #1
          (?<=  Lookbehind Group
                    \b  Word boundary
                    \d  Any digit (0..9)
                    \d  Any digit (0..9)
          )  End Lookbehind Group
)  End Group #1
e  Literal character “e”
\b  Word boundary
 (1 (?<=< \b \d <) |1 (?<=< \b \d \d <) 1) e \b

Similar Messages

  • CS3: grep search to replace part of a string

    Can I do a grep search for a string of text but only replace a portion of the string while leaving the remainder intact?
    iMac G5, OS 10.5.5

    In addition to Eric:
    Find "some search string", Replace "some replacement string " also replaces part of the string, not touching anything...
    But the GREP search has two advantages: First, if you define formatting in the Replace field (italics, superscript, a character style), only the 'search'/'replacement' part will be affected, rather than the entire found string (as in regular search).
    The second big advantage is you can use any regular GREP single character wildcard in the 'left' and 'right' (matching-but-not-marking) parts. A few useful examples: '\d' (digit), '\l' and '\u' (lowercase and uppercase), '.' (any character), or even '[a-f]' (lowercase 'a' to 'f'). The only limitation is that you cannot use the once, zero-or-more, or once-or-more modifiers -- the strings must have a fixed length. FYI, those three modifiers are, respectively, ?, *, and +.
    This restriction does not apply to the 'middle' string, the one you are going to replace anyway -- use whatever GREP you want.

  • [CS3] GREP search first ocurence only

    Hi!
    I have an alphabetical list:
    Asdfg
    Awert
    Bsdfg
    Bwsd
    Csdfg
    Cwsd
    etc
    Is it possible to grep search first occurrences of A:s, B:s, C:s etc and then apply some formatting?
    ie search first line that starts with A, apply formatting, ignore following lines witch start with letter A and search first line that starts with B, apply same formatting...
    Thanks

    Oh allright, this one sets the paragraph style "Index head" as well.
    nextpar = app.activeDocument.selection[0].paragraphs[0];
    do
    nextletter = nextpar.contents[0].toUpperCase();
    nextpar.insertionPoints[0].contents = nextletter+"\r";
    nextpar.insertionPoints[0].appliedParagraphStyle = "Index head";
    while (nextpar.contents.length > 0 && nextpar.contents[0].toUpperCase() == nextletter)
      if (nextpar == nextpar.insertionPoints[-1].paragraphs[0])
       exit(0);
      nextpar = nextpar.insertionPoints[-1].paragraphs[0];
    } while (nextletter < "Z");
    It's surprisingly slow, on a 3 column/4 page index... but it still beats doin' it manually, 'cause you can sit back and clean your fingernails or something like that.

  • Question for scripting gurus: GREP search, change case make Smallcaps

    I have no knowledge of scripting at all, but this question keeps coming up during training sessions: is it possible to (java)script this:
    - Do a GREP search \u\u+
    - Change case to lowercase
    - Apply SmallCaps (or: apply character style)
    this would allow to search for acronyms and change them to smallcaps (or, even better: apply a character style with small caps and tracking)
    I know it is easy for OpenType smallcaps (do a GREP search, change to OT smallcaps) but this doesn't really change case. And some fonts used aren't OT.
    Anyone?
    Would be VERY apreciated!!

    But Harbs is a seasoned scripter who knows he'll get flamed if one of his scripts "just does not work" ;)
    Well, now that you mention it, the script is not really foolproof. It's a quick and dirty script which I threw together very quickly. It's missing any error checking, some of the variables global, and it's not in a private namespace. These are all things which could cause it to "just not work" ;-)
    Here's a more foolproof construct... (and it'll work on the current story if selected, or the whole document if there's no story selected) It will create a new character style if one does not exist and work on character styles within style groups as well. I wrapped the whole script in an anonymous function to give it a unique namespace as well.
    (function()
    if(app.documents.length==0){return}
    var doc=app.documents[0];
    // Change the following to your style name!
    var character_style_name = 'Small Caps';
    try{var range = app.selection[0].parentStory}
    catch (err){var range = doc}
    //comment out next line if you do not want styles.
    var charStyle = GetCharacterStyle(character_style_name,doc);
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat="\\u\\u+";
    var finds=range.findGrep();
    for (var i=0;i<finds.length;i++){
    finds[i].changecase(ChangecaseMode.lowercase);
    //comment out next line if you do not want styles.
    finds[i].applyCharacterStyle (charStyle)
    //uncomment next line if you do not want styles.
    //finds[i].capitalization=Capitalization.smallCaps;
    function GetCharacterStyle(styleName,doc){
    var charStyles=doc.allCharacterStyles;
    for(var i=0;i<charStyles.length;i++){
      if(charStyles[i].name==styleName){
       return charStyles[i];
    return doc.characterStyles.add({name:styleName,capitalization:Capitalization.smallCaps});

  • GREP searches from top of story?

    I've set up a GREP expression to find some material I need to delete, but I need to check each instance before I actually delete it. Unfortunately, the GREP expression occasionally finds text that I want to keep, so it's not bullet proof.
    When I first set up my GREP expression, it worked fine -- it would find the next occurrence of the expression after the insertion point when I type a keyboard shortcut for the "GREP Find Next" command.
    Suddenly, and I don't know why, it changed its behavior so that instead of finding the next instance of the GREP expression after the current insertion point, it finds the first occurrence in the story, which is pages away from where I want to be working.
    Is there some way to tell GREP (or any Find search) to look from the insertion point rather than from the top of the document? It seems to have both behaviors as options, but I don't know why it chooses one over the other.

    Well, having done a little more work, I think the problem may result from a look-behind that I added to the beginning of the string.
    Basically, I have about 500 abstracts, each has a long list of authors, with punctuation as follows: SMITH, J.S., affiliation, email; JONES, S.J., affiliation, email; etc.
    I need to get rid of the affiliations, emails, and semicolons; keep the Author name and initials; and apply a script of mine to put the last name in title case, resulting in
    Smith, J.S., Jones, S.J., etc.
    There are some typos and unusual names, so I need to do this one by one rather than with a global search, but I want to be efficient. I want to run my case-change script on the last name, then trigger a GREP search that will select the affiliation and email, which I can then look over to confirm, then delete. (Affiliation may be full of all kinds of punctuation).
    Currently I'm using
    .+?[;\r]
    ...which selects from the insertion point to the next semicolon or the end of the paragraph, whichever comes first. This one works, but I first need to move the insertion point past the initials, which takes more keystrokes.
    Since the author initials always end with a period followed by a comma, but I don't want to delete those, I thought I'd add a look-behind so that the GREP would select all the text from (but not including) a period-comma to (and including) the next semicolon:
    (?<+\.,).+?[;\r]
    The problem is that instead of searching from the insertion point, it goes to the beginning of the file and grabs the first occurrence of the pattern, which is the first already-corrected address (since there are no semicolons left, it selects from just after the first author's initials to the paragraph end).
    Anyway, if anyone has some ideas (including "sorry, GREP just behaves this way with look-behinds") I'd appreciate any help.

  • GREP - search for anything except one character

    Trying to figure out if I can say this in GREP or not....
    I want to search for any character that's in a Superscript character style except for registration-mark symbols.  Is there a way to exclude one character from a search?
    Thanks, Phyllis

    Absolutely. Remember the '^' character that indicates 'start of paragraph'? Well ... apparently whoever devised GREP ran out of useful characters, because it's used again in the "exclude" group. It works like this:
    [0-9fuzzy]
    looks for a single character out of the set '0' to '9' (inclusive), 'f', 'u', 'z', or 'y'. Throwing in the hat reverses the query:
    [^0-9fuzzy]
    looks for any old single character except those in the set.
    The Registered mark has a shortcut of its own in the regular Find -- ^r -- so presumably it's "~r" in GREP mode. If not, copy-and-paste one from your text. So your GREP search should be (with Superscript formatting)
    [^~r]
    This marks only the next non-registered character; to find longer strings you can safely use
    [^~r]+
    -- which translates into "any string in superscript, one character or longer, and not containing the Registered mark". Yes, the short version is a bit easier to type.

  • Excluding a character from "Change to" box that is in "Find what" box in GREP search

    Hello all! I am a first time poster but have been lurking around the forums for a few months. I'm trying to produce an InDesign document for a book I'm putting out, and there is a section where I have the following text:
    |  TAB  |1.|  TAB  |Lorem ipsum dolor etc.
    The text doesn't literally say tab, I jsut wanted to highlight that there is a tab of white-space on either side of the number for the line. This occurs numerous times in numerous chapters in the endnotes section. I want to remove the tabs so that the result is:
    1. Lorem ipsum dolor etc
    2. Lorem ipsum dolor etc
    3. etc etc
    I have identified that the way to find these sections is to use the GREP search function with \t\d+.\t. The + is there because the numbers go into the double digits in most chapters for the references. However, I do not want to remove the numbers, just the tabs. Is there any way to add an exclude feature to the "Change to" window of the search function? I've tried just leaving it as \d., but that literally changes the text to
    \d. Lorem ipsum dolor etc
    That's not good. I'm trying to avoid having to do all of this by hand, and of course by the time I get a resolution I'll probably have been better off doing it manually, but I'm looking toward the future and trying to ascertain the best way of streamlining such a process short of not having that kind of format in the first place when receiving the file from my employer
    Many thanks for your advice,
    David

    Peter,
       Just to affirm your assistance, this worked for me. I still don't understand the advanced search features perfectly, but I got the formatting fixed without having to sift through it manually. I found that replacing with "$2. " (minus the quotes) worked well. However, I noticed that searching for (\d). would turn up a digit followed by ANY kind of punctuation, not just a period. I assume therefore that . must mean something different in GREP than I'm thinking it does. I just wanted to find any digit before a full-stop. At any rate, that is something I can find a table of GREP search terms for. I didn't understand the $2 thing until I monkeyed with it. I'm typing now for future generations of newbies that might stumble upon my post. The $2 ignores the second character in your "Find what" field. So for example, if instead you had two tabs then a digit then a tab, you could search:
    Find what: (^\t)(\t)(\d)(\t)
    Change to: $3.
    This would take any occurrence of two tabs, a number, and a tab and replace with a period, ignoring and therefore not changing at all the number. The $3 is saying "ignore the third search term", in this case, the \d.
    A better approach would be to use +. This means "any time you see one or more occurrences of the searched-for character". This would look something like:
    Find what: (^\t+)(\d+)(\t+)
    Change to: $2.
    Here you are saying "Any time you see one or more tabs followed by one or more numbers and then followed by one or more tabs, ignore the digit, delete the tabs before and after, and add a full stop after the number. This is a very powerful search feature, once you understand what you're doing anyway. Hope that is helpful to someone at some point.

  • Using footnote markers in a GREP search

    In a 300 page document, with hundreds of footnotes, I want to insert thin spaces between single endquotes and footnote markers. The easiest way seemed a GREP search and repace. I search for (\’)(~F) and replace it with $1~<$2. The result is ’ ’ (endquote-thin space-endquote). When I try to replace AB to A-thin space-B in the same way, the result is right. So what's going wrong? (I also tried ~] for the endquote.)
    (By the way, I have a workarround, but I'd like to understand how GREP searches work.)

    Footnotes aren't really a part of the semi-official GREP definitions, and I imagine the Adobe programmers had to fix a couple of workarounds to make them work at all. They are not simply single characters (quotes, spaces, and possibly text variables are) but "contain" lots of other information, just like anchored objects do. That could be the reason they don't Play Nice with regular GREP operations.
    In this particular case, you can work around it searcing for but not replacing the footnote marker code. Look for
    (\')(?=~F)
    and replace with
    $1~<
    The combo (?=~F) will find but not include the footnote code, and thus nicely circumvent the problem.

  • Script or GREP search line for missing quotation marks (opening or closing)

    Hi there,
    I've being trying to figure out a GREP search that will help me find quotations that haven't been opened or closed properly. Does anyone know if there exists a script that will mark/help me find the quotation marks that incorrectly stand alone? A GREP search line would be fine too.
    Following is an example - just to make sure I made myself clear:
    'why is the closing quotation mark missing after the question mark? I asked.
    'I don't know, this line seems to be fine, with opening and closing quotation mark,' I answered.
    Although this line is missing an opening quotation mark.'
    Hope somebody can help me, I'm pretty sure I'm not the first person searching for a solution on this issue - sorry, I'm not to bright with scripting or GREP.
    Thnx.
    Gijs

    As you say, it's not waterproof, but it is really helpfull, thanks. The unclosed quotation are easy to find this way.
    In Dutch we mainly use single quotation marks (double quotation marks are only used for quotations within quotations). This brings an extra dimension to the issue, since the apostrophe and single quotation mark are the same character. So a phrase like ' I'm having problems finding unopened quotations' with your GREP suggestion will mark the apostrophe in I'm as the closing quotation mark.
    So what I'll do is:
    1. find unclosed quotations ‘[^’]+?‘ and mark them with a character style WARNING;
    2. GREP search ’[^‘]+?’ two following closing quotation marks and make them C=100;
    3. GREP search ’[^‘’]+?’ the correct quotations and mark it all K=100;
    4. Do a regular search for '^$ any apostrophe/quotation mark followed by a letter and mark them all K=100;
    5. Do a regular search for any closing quotation mark left in C=100 and manually WARNING-mark the ones that need to be looked at by the editor.
    Step 4 is a bit tricky since any error like 'I agree,'he said (no space after quotation mark) will be marked back to K=100 as well, but those errors I'll probably notice since they're underlined by the grammar control option.
    Thanks again for the help.

  • GREP search crashes InDesign

    Hi,
    I have a script which imports XML and formats it. As part of the formatting, there's numerous GREP searches which remove redundant spaces, returns and so on.
    One in particular crashes InDesign and it's driving me nuts.
    It's supposed to remove redundant returns in a table:
    // GREP Search for redundant returns
    app.findGrepPreferences = app.changeGrepPreferences = null;      
    app.findGrepPreferences.appliedParagraphStyle = "ArticleMinister";
    app.findGrepPreferences.findWhat = "\r$";
    app.changeGrepPreferences.changeTo = "";
    app.activeDocument.changeGrep();
    The problem is there's an XML closing tag between the carriage return and the end of the para, i.e. data{return}</closingtag>, but it works fine when the XML is data</closingtag>{return}.
    Any assistance would be most appreciated.

    Hi Vamitul,
    Thanks very much for the reply and it makes perfect sense.
    This script creates quite a complex document and, for some reason, moving the {return} outside the XML tags makes a mess of the document. I do not know why but I suspect that some of the 'clean up' non-GREP search and replace commands in the script are ignoring the XML data - perhaps not but I cannot for the life of me work out why a simple change is making the text a real mess.
    So the 'harder fix' sounds like something worth pursuing as this is the last step in a long process. Do you have any more information about checking the xmlContents? I don't expect anyone else to do my work for me, but advanced (or even intermediate) scripting is something I struggle with.
    Cheers,
    Simon.

  • Adding GREP search to FindChangeByList script in CS4

    I'm trying to remove numbers from a baseball box score pulled from the Internet.
    The file has 10 numbers across separated by tabs and I only need six of the numbers not all 10
    St. Lucie Mets
    Player,Pos         AB     R     H     2B     3B     HR     RBI     BB     SO     AVG
    Daniel Muno, 2B    4     1     1     0     0     1     1     0     2     .259
    Robbie Shields, DH     4     0     2     1     0     0     0     0     1     .471
    This GREP search works in FindChange in InCopy/InDesign (using CS4)
    (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d)
    This works in the Change field
    $1 $2 $3 $7 $8 $9
    However, when I try to add this to a FindChangeByList script, it generates an error. So my syntax, logic or both is flawed.
    What should I do to fix it?
    grep    {findWhat:"(\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d) (\t\d)"}    {changeTo:"$1 $2 $3 $7 $8 $9"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double spaces and replace with single spaces.
    Thank you,
    Keith

    Hi Jongware,
    Thank you for the reply.
    I tried the double slashes and get an Error 25. So something I'm doing in the Search/Replace portion isn't working.
    However, I did have success with changing a style by using a GREP search. The line below works with the double slashes, just not the Find/Change lines:
    grep
    {findWhat:"\\t\\d\\t\\d\\t\\d\\t\\d\\t\\d\\t\\d\\t\\d\\t\\d\\t\\d"}
    {appliedParagraphStyle:"Z BB Box Exp Batting 07T"}
    {includeFootnotes:true, wholeWord:false, caseSensitive:false}
    //Changes style

  • GREP Search - Save to file

    Hello,
    I wonder if it's possible to do a GREP search in an Indesign CS3 document, then save the results to file (like .csv).
    Thanks
    Marco Lugli

    Sure it is possible.
    Assign your found texts to a variable, write the variable to a text file.
    myVar = "";
    // add text to variable
    myVar += "text\tsecondtext\n";
    newFile = new File ("~/Desktop/mycsvfile.csv");
    newFile.open('w');
    newFile.write(myVar);
    newFile.close();

  • Indesign grep search on page by page using javascript

    Hi,
    Is it possible to grep search a word page by page instead of searching in whole document..
    If it is possible, please suggest how to do this.
    Thanks,
    Gopal

    Hi Gopal,
    You can't search directly in page. Instead you can search by pages[n].textFrames[x].texts[0].findGrep().
    Regards,
    Ramkumar .P

  • Help need for GREP search to remove Digits

    Hello every one,
    I have text with reference numbers like following, i need to remove the numbers in front of the every paragraph beginning, but some digits following space, some digits are without space. Please help me to remove these digits with GREP search or MS Word or any other ways
    Before:
    1 Apple
    2Ant
    4 Animals
    55 Flowers
    56Doctor
    466 Painters
    467Teacher
    After:
    Apple
    Ant
    Animals
    Flowers
    Doctor
    Painters
    Teacher
    Thanks,
    Siva

    Awsome, Thanks a lot Harbs I have tried from few days but not worked, you have done it in a couple of minutes    

  • Grep Search / Text Search + Past Searches

    Is there a way to clear out previous GREP searches / Text Searches (Find/Change) from the "Find what" and "Change to" boxes? Is this document specific or an ID Preference issue?

    Hi Eugene,
    Thanks for the info, but I am not looking to make shortcuts. I want to delete all the pre-filled text that appears from previous searches. For example in the original image this is represented as
    http
    and the dropdown box is blue indicating that there is stored data. Having cleared ALL ID Preferences fixes the problem, however, I don't want to be forced to delete ALL preferences to delete this data. See pic below

Maybe you are looking for