[GREP] – find/replace only first comma in paragraph

Is it possible to find and replace only the first comma in paragraph with certain paragraph style with end of paragraph character using GREP search? Or in other words – to split paragraph into two paragraphs by replacing the first comma in paragraph with end of paragraph character?
Claudius

That's an interesting problem, and I think it takes at least two steps.
The expression (^[^,]+),\s* will find all text from the beginning of a paragraph up to the first comma, which might be followed by whitespace and allows you to use the $1 operator in the change to field to save the text up to the comma, but replace the comma and following whitespace with anything you like. However, as soon as you replace that with a paragraph break you've created a new paragraph to search and you end up breaking at every comma.
Instead you need to insert a stand-in symbol of some sort with a unique character style applied (so it won't get picked up any other way), for instance change to $1% and apply the style named "break" which does no formatting but flags the text for the next search.
Now search for % with the "break" style and replace with the paragragh break (and no style).
You should probably now search for .+ with the break style and change to nothing (or $0 for found text), and remove the style, just to be clean.
There's still one problem, though, and that's that all the new paragraphs start with a lower-case character unless the first word after the comma happened to be capitalized. You could now search for ^. to find the first character in each paragraph and use the change format to apply a character style that assigns all caps, but that's really an ugly way to work.
All of this will fall apart, too, I think if you have nested or GREP styles affecting the beginning text or the first character in any paragraph that you wind up with.

Similar Messages

  • Grep find/replace to clean-up texts

    Hi,
    I want to use The ID GREP find/replace to clean-up a imported text with at every line a carriage/return (CR).
    (space)CR -> (space)
    a_wordCR -> aword(space)
    CRCR -> CR
    How can I perform this with Grep expressions ?
    Thanks

    In the first and 3rd replaces, you want a CR replaced with nothing; in the 2nd one, with a space. So it's not possbile to do this with one single "magic" search and replace -- Grep is not magic
    This query will take care of the returns:
    (?<=[\r ])\r
    (replace with nothing). It finds returns with at their left either a return or a single space.
    This one
    (?<=\w)\r
    (replace with space) will change a return after a word character to a space. "Word character" is a bit undefined -- it appears to be at least A-Z (including accented characters), 0-9, and Greek/Cyrillic characters. In case of a problem, you could try
    (?<=[[:alpha:]])\r
    instead -- forcing 'alphabetic' characters only.

  • Find & Replace the text and apply paragraph style in indesign CS2.

    Hai below script are working in cs4 - cs5.5. i need to run the script in indesign cs2.
    can you please help.
    Main();
    function Main() {
        var foundItem;  
        var doc = app.activeDocument;
        //app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
    app.findTextPreferences.findWhat = "^p";
           //app.findTextPreferences.appliedParagraphStyle = "head";
        var foundItems = doc.findText();
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("content body indent"), false);
         app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
         var myDocument = app.activeDocument;
    //Clear the find/change text preferences.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    //Search the document for the string "copy" and change it to "text".
    app.findTextPreferences.findWhat = "^p";
    app.changeTextPreferences.changeTo = "^p";
    myDocument.changeText();
    //Clear the find/change text preferences after the search.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    abc();
    function abc() {
        var foundItem;  
        var doc = app.activeDocument;
        //app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
    app.findTextPreferences.findWhat = "*";
           //app.findTextPreferences.appliedParagraphStyle = "head";
        var foundItems = doc.findText();
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("RealEstate"), false);
         app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
         var myDocument = app.activeDocument;
    //Clear the find/change text preferences.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    //Search the document for the string "copy" and change it to "text".
    app.findTextPreferences.findWhat = "*";
    app.changeTextPreferences.changeTo = "";
    myDocument.changeText();
    //Clear the find/change text preferences after the search.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    ab();
    function ab () {
        var foundItem;  
        var doc = app.activeDocument;
        app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
        app.findTextPreferences.findWhat = " ^ ";
    app.changeTextPreferences.changeTo = " ";  
        //app.findTextPreferences.appliedParagraphStyle = "head";
        var foundItems = doc.findText();
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("day"), false);
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
         var myDocument = app.activeDocument;
    //Clear the find/change text preferences.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    //Search the document for the string "copy" and change it to "text".
    app.findTextPreferences.findWhat = "^";
    app.changeTextPreferences.changeTo = "";
    myDocument.changeText();
    //Clear the find/change text preferences after the search.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;

    @s_ashok – you'll find the right methods and properties in the CHM file for InDesign CS2 at:
    http://www.jongware.com/idjshelp.html
    Just a few hints:
    InDesign CS2 does not support GREP search/replace, so every line in your code that points to GREP does not work.
    Further: "app.findTextPreferences" and "app.changeTextPreferences" were "app.findPreferences" and "app.changePreferences" in InDesign CS2. And then there were no "findChangeTextOptions" or any counterpart for that in CS2…
    That should get you running…
    I have no InDesign CS2 installed to debug, so this is all I can say…
    Uwe

  • Grep to replace only part of the found text

    I'm using ^.+~> to search the begging of a paragraph up to an EN space, but is it possible with GREP to format just PART of the string found?
    There are roman numerals that precede a period and an EN space and I want to apply formatting to just the roman numerals, leaving the period and EN space alone.
    I did found one post that mentions using "some" but I'm not familiar enough with GREP to know how it works.
    Can anyone commend a good source for GREP coding?
    Thanks,
    Ken

    Try this:
    ^(.+)(?=\.~>)
    I just changed your original code to use the period and en-space as a positive lookahead -- it'll only find characters at the beginning of the line if they're followed by a period and an en-space, but will not include them as part of the found text.
    If these items all have the same paragraph style applied to them and that style isn't used anywhere that you wouldn't want the formatting, I'd also consider setting this up as a GREP style. You could also do it as a nested style applying your character style up to (.~>). (Don't include the parantheses - I was just trying to make it clear what the expression to use is.) 
    Hope that helps.

  • Using Grep to find/replace

    I'm trying to find out how to use GREP in find/replace to chage the formatting of some text that comes in from a spreadsheet.
    I worked out the GREP query "~b(\d\d)~b", which finds a paragraph return, followed by two digits, followed by another paragraph return
    and then it is replaced by "\t $1~b", which is a tab, the two found digits and a para return.
    What i need to do is to amend the query to find ANY number of digits, (which may be comma delimited: eg 23, 36, 48 ,50), and then replace with a tab + found text.
    I suppose what I'm looking for is a way for the query to find "any text between two paragraph returns, no matter what tthe length", but I don't know how to do this.All the Wildcard options seem to find just one exampler (one digit, one character etc)

    And you came so far
    The operators for repeat are ? (zero or once), * (zero or more) and + (once or more). You can also specify exact numbers: {at least,up to}.
    All of these operators are "greedy" by default -- they will match as much as possible. To match as least as possible (which I'm sure you'll come up against, sooner or later), add another ? after the repeat expression.
    So this will find one digit, then optionally another (which will always be included):
    \d\d?
    and this one digit, then zero or as much as ten million million zillion:
    \d\d*
    which is functionally the same as
    \d+
    And this will find between 3 and 8 digits but will forced to use the shortest possible match:
    \d{3,8}?
    That said: A quick & dirty solution for your actual problem is to find any amount of digits, spaces, and comma's:
    ~b[\d, ]+~b
    (we need the plus here because otherwise it would also match an empty line). The [..] brackets an Inclusive list --- it will match any of the single codes inside.
    A more complicated but 'neater' way is to search very specifically only for number, comma, space, number sequences -- it's neater because that way malformed lines (comma without a space) will be skipped!
    (It also introduces another code -- the parentheses operators. Look them up in a good GREP reference --lost of people are enthousiastic about Peter Kahrel's O'Reilly title, because it's about using GREP in InDesign.)
    ~b\d+(, \d+)*~b

  • Why not there a "Find/replace in Grep style" inside the Para style?

    Whenever I type a digit in my text, it should be colored red as per style. I do this by grep style inside the para style, but now I need to insert brackets before and after of the digit(s), i realize that there is no replace option in grep style in the para style. Why not it be there a "find/replace" instead "find" only as it now appears?

    Ya, this is simple, finding a specific para style with digit and change them, when the book in first pass. But while in the correction pass of the same book, whenever we are inserting more text into the document, there are chances to be unaware of the digit style that, it should be surrounded by brackets, and it happened earlier so I have a thought of it. Again, while paginating a book having more than 350 - 600 pages, and 3 to 4 guys working in it, I think this may work.
    Expecting your valuable comment on this.
    Thangaraj Mohan.

  • How to replace only the first specified character in a string and leave other occurrence of the character alone.

    Hello my Friends:
    I have a string that looks like this in a column:
    Hello, World, Hello, Planet
    I want to replace only the first occurrence so that the result looks like this:
    Hello World, Hello, Planet
    Working on some bad data source.
    I need to replace the character regardless of it's location as long as it is the first.
    I tried something like this, but I soon discovered that if the comma or character is missing the the string may get truncated or altered. If there are no characters in the string, then I want to simply leave it alone.
    Here is where I am at:
    DECLARE @MyValue NVARCHAR(MAX) = 'Hello, World, Hello, Planet';
    SELECT MyString = STUFF('Hello, World', CHARINDEX(',', @MyValue, 0), 1, ' ');
    Thanks my friends.

    I have a string that looks like this in a column:
    Hello, World, Hello, Planet
    Why doesn't it say Hello Kitty?
    Oh, sorry about that. Anyway:
    SELECT MyString = CASE WHEN CHARINDEX(',', @MyValue, 0) >= 1
                           THEN STUFF(MyString, CHARINDEX(',', @MyValue, 0), 1, ' ')
                           ELSE MyString
                     END;
    Erland Sommarskog, SQL Server MVP, [email protected]
    Erland, love you sense of humor!! :)
    Thanks for the solution.

  • Grep style: identify the letter l first in a paragraph

    Grep style: I want to add a character style to the letter l, but only if it is the first character in a paragraph and the next character is a single space. Basically, I would like to change the font to zapf dingbats, but only for the letter l when it is the first character  in a paragraph. This will generate a bullet character as first letter. has anyone any idea how this grep search should be? The query should look for the letter l and a single space first in a paragraph!

    The GREP for this would be:
    1. Start of paragraph: ^
    2. Followed by a single letter "l": l
    3. A positive lookahead for a single space: (?= )
    ^l(?= )
    Uwe

  • Please explain me, how to remove an usb stick or memory chip? With experiences only in pc:s, I do not find on my first apple e.g. MacBook Air a solution. Until now I have succeeded to destroy one chip full of photos and - there's no life more in the port.

    Please explain me, how to remove an usb stick or memory chip? With experiences only in pc:s, I do not find on my first apple e.g. MacBook Air a solution. Until now I have succeeded to destroy one chip full of photos and - there's no life more in the port...
    Someone told me just to remove the chip in clicking it to the trash can and voilá - it would be done. But as I did so, on the screen appeared a text which let me know, that that way had been the wrong one...
    I should have clicked Finder plus something.... which I do not now remember but which was then not found behind the Finder.
    So please would someone be so kind and tell me, where I can find explanations for the most simple functions. The manual I got does not include a clue.
    Thank you!

    First make sure that no application is using or has open any files on the disk. Then:
    Click and drag the disk icon on the desktop to the trash. Wait for the system to recognize the action, and the icon should disappear from the desktop. It is then safe to remove the device.
    Alternatively, you can secondary click on the disk icon, and then primary click "Eject (name of disk)". Wait for the icon to disappear off the desktop, and then it is safe to remove the drive.
    Here is a detailed help document on the subject.
    http://docs.info.apple.com/article.html?path=Mac/10.7/en/mchlp1056.html

  • How do I 'Find & Replace' with control characters - paragraph, carriage return, tab

    In Pages 4.3 (Pages '09) I could insert special characters into the Find & Replace fields.  It was great.  Excellent way to clean up & recover text from a pdf or html.
    In Pages 5.2 that capability seems to be gone.  When I turn on the special characters [Show Invisibles - shift-cmd-I], I can highlight said invisible, copy it, then paste it into the Find&Replace field.  Nope.  It goes in as a space, and the Find command only finds spaces.  Not the invisible that I was looking for.
    This was a major feature for me, folks.  Much better than Word's approach.  Now it is gone (I fear), and the Find & Replace is worse than Word's.
    How can I recover/attain this feature?

    I have struggled to find this "feature" for a while.
    It CANNOT be that Apple stripped out a core capability of even a basic text editor.
    Apple, a reply here because this is a F%$#$%^ joke if true.

  • Find / Change Replace "End of story" by Paragraph

    Hi tehre,
    I tried unsuccessfully to find out how to manage to put a paragraph to the end of story to the multiple textframes automatically. There must be some way! Am I right?
    Thank you!

    Hi Scott,
    See the IMG please to understand me more:
    Each textframe  has the "#" hidden character on the very end. I want to put there a paragraph to the very end of each textframe I selected. I imagined something like this:
    Open "Find / Change" dialog box
    Find the "#" {End of Story}
    And replace it by "¶ #" {Put the paragraph before the very End of Story}
    I am merging multiple textframes, copy them and put the text to the different indd document. But if there is not a paragraph on the end of the textframes which I am merging, all the text joins together and I have to put paragraphs manually there afterwards. {I am merging 4 textframes into one, so i have to put there at least 3 paragraphs. I have 350 items, which means about thousand paragraphs together to be put manually.}
    Runnig ID CS6.
    Thank you!

  • GREP: Conditional Replace

    Say I want to replace all [ with << and ] with >>. However, I only want to replace the brackets where a # occurs between them. Here are two examples:
    [Carfrae, 2006 #2959]
    [A]
    I would like to have the brackets repalced in the first isntance only. The text within the brackets should remain as is in all instances.
    How would I go about it? Thanks for your help.
    S.

    Sorry for being out of the loop all day. I wasn't hiding unless you call trying to find a golf ball in the woods hiding. I will try to answer some of the questions raised.
    The solution I posted was written precisely for the example given. GREP finds patterns of text so one must define the "pattern" in order to create the GREP Expression.
    ? has a variety of meanings depending on how it is ussed
    ? = zero or One Time
    ?? = zero or One Time shortest match
    +? = one or more times shortest match
    ?i = case insensitive On
    Fortunately all of these metacharacters are contained in the numerous fly out menus associated with GREP Find/Change so we need no memorize them, only learn the effect that they have in a search.
    Original Post:
    (\[)(\w+,\s\d+\s#\d+)(\])
    CHANGE:
    $2
    Search divided into three components -- each separated by (---)
    The first (----) looks for a closed bracket (since [ and ] have "special" meaning in GREP we need to precede them with a backslash to indicate we want to find the literal occurrence of the Bracket(s)
    the Second (-----) looks for any word character  \w           
    one or more times    + 
    followed by a comma  ,
    then a space \s
    then the literal # (# has no special meaning in GREP so # finds #)
    followed by any character \d
    appearing one or more times  +
    the third (----) finds the Closed Bracket
    In the Change
    $2 indicates the desired change will be made to the second found "section" and the Open and Closed Brackets will disappear.
    If Change read
    $0 that means change applies to ALL found items
    $1 means the change applies to what is found in first division ie- Open Bracket
    $2 means the change applies to what is found in second division
    $3 would apply the change to the third --ie Closed Bracket
    The use of "shortest match" deals with GREP's penchant for being Greedy. I won't explain here but suffice it to say for starters that GREP thinks in terms of paragraphs so when it has a search expression that has a potential for being greedy and therefore find too much - its appetite stops at a carriage return.
    The solution tendered worked with the example by including required characters that did not appear in the bracketed material not desired to be found. That having been said there are likely a number of ways to write an expression that would have the same effect. I stop when I have found whatever works and consider myself lucky.

  • Find Replace from Textfile with regex

    Hello.
    I'm wondering if anyone knows about an existing script that does a find/replace by list like the script "FindChangeByList.jsx" that comes with every InDesign installation.
    This consists of tow parts, the script itself with the functionality and a simple textfile where you have simple one-liners capable of find/replace with regex.
    the Textfile:
    //FindChangeList.txt
    //A support file for the InDesign CS4 JavaScript FindChangeByList.jsx
    //This data file is tab-delimited, with carriage returns separating records.
    //The format of each record in the file is:
    //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
    //Where:
    //<tab> is a tab character
    //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
    //findProperties is a properties record (as text) of the find preferences.
    //changeProperties is a properties record (as text) of the change preferences.
    //findChangeOptions is a properties record (as text) of the find/change options.
    //description is a description of the find/change operation
    //Very simple example:
    //text          {findWhat:"--"}          {changeTo:"^_"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double dashes and replace with an em dash.
    //More complex example:
    //text          {findWhat:"^9^9.^9^9"}          {appliedCharacterStyle:"price"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find $10.00 to $99.99 and apply the character style "price".
    //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
    //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
    //as shown in the example below:
    //{findWhat:"\\s+"}
    grep          {findWhat:"  +"}          {changeTo:" "}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double spaces and replace with single spaces.
    grep          {findWhat:"\r "}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a space And replace with single returns.
    grep          {findWhat:" \r"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a space and replace with single returns.
    grep          {findWhat:"\t\t+"}          {changeTo:"\t"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double tab characters and replace with single tab characters.
    grep          {findWhat:"\r\t"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a tab character and replace with single returns.
    grep          {findWhat:"\t\r"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a tab character and replace with single returns.
    grep          {findWhat:"\r\r+"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double returns and replace with single returns.
    text          {findWhat:" - "}          {changeTo:"^="}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all space-dash-space and replace with an en dash.
    text          {findWhat:"--"}          {changeTo:"^_"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all dash-dash and replace with an em dash.
    The script:
    //FindChangeByList.jsx
    //An InDesign CS5.5 JavaScript
    @@@BUILDINFO@@@ "FindChangeByList.jsx" 3.0.0 15 December 2009
    //Loads a series of tab-delimited strings from a text file, then performs a series
    //of find/change operations based on the strings read from the file.
    //The data file is tab-delimited, with carriage returns separating records.
    //The format of each record in the file is:
    //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
    //Where:
    //<tab> is a tab character
    //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
    //findProperties is a properties record (as text) of the find preferences.
    //changeProperties is a properties record (as text) of the change preferences.
    //findChangeOptions is a properties record (as text) of the find/change options.
    //description is a description of the find/change operation
    //Very simple example:
    //text          {findWhat:"--"}          {changeTo:"^_"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double dashes and replace with an em dash.
    //More complex example:
    //text          {findWhat:"^9^9.^9^9"}          {appliedCharacterStyle:"price"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find $10.00 to $99.99 and apply the character style "price".
    //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
    //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
    //as shown in the example below:
    //{findWhat:"\\s+"}
    //For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html
    //or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
    main();
    function main(){
              var myObject;
              //Make certain that user interaction (display of dialogs, etc.) is turned on.
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
              if(app.documents.length > 0){
                        if(app.selection.length > 0){
                                  switch(app.selection[0].constructor.name){
                                            case "InsertionPoint":
                                            case "Character":
                                            case "Word":
                                            case "TextStyleRange":
                                            case "Line":
                                            case "Paragraph":
                                            case "TextColumn":
                                            case "Text":
                                            case "Cell":
                                            case "Column":
                                            case "Row":
                                            case "Table":
                                                      myDisplayDialog();
                                                      break;
                                            default:
                                                      //Something was selected, but it wasn't a text object, so search the document.
                                                      myFindChangeByList(app.documents.item(0));
                        else{
                                  //Nothing was selected, so simply search the document.
                                  myFindChangeByList(app.documents.item(0));
              else{
                        alert("No documents are open. Please open a document and try again.");
    function myDisplayDialog(){
              var myObject;
              var myDialog = app.dialogs.add({name:"FindChangeByList"});
              with(myDialog.dialogColumns.add()){
                        with(dialogRows.add()){
                                  with(dialogColumns.add()){
                                            staticTexts.add({staticLabel:"Search Range:"});
                                  var myRangeButtons = radiobuttonGroups.add();
                                  with(myRangeButtons){
                                            radiobuttonControls.add({staticLabel:"Document", checkedState:true});
                                            radiobuttonControls.add({staticLabel:"Selected Story"});
                                            if(app.selection[0].contents != ""){
                                                      radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
              var myResult = myDialog.show();
              if(myResult == true){
                        switch(myRangeButtons.selectedButton){
                                  case 0:
                                            myObject = app.documents.item(0);
                                            break;
                                  case 1:
                                            myObject = app.selection[0].parentStory;
                                            break;
                                  case 2:
                                            myObject = app.selection[0];
                                            break;
                        myDialog.destroy();
                        myFindChangeByList(myObject);
              else{
                        myDialog.destroy();
    function myFindChangeByList(myObject){
              var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
              var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
              var myStartCharacter, myEndCharacter;
              var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
              if(myFindChangeFile != null){
                        myFindChangeFile = File(myFindChangeFile);
                        var myResult = myFindChangeFile.open("r", undefined, undefined);
                        if(myResult == true){
                                  //Loop through the find/change operations.
                                  do{
                                            myLine = myFindChangeFile.readln();
                                            //Ignore comment lines and blank lines.
                                            if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")|| (myLine.substring(0,5)=="glyph")){
                                                      myFindChangeArray = myLine.split("\t");
                                                      //The first field in the line is the findType string.
                                                      myFindType = myFindChangeArray[0];
                                                      //The second field in the line is the FindPreferences string.
                                                      myFindPreferences = myFindChangeArray[1];
                                                      //The second field in the line is the ChangePreferences string.
                                                      myChangePreferences = myFindChangeArray[2];
                                                      //The fourth field is the range--used only by text find/change.
                                                      myFindChangeOptions = myFindChangeArray[3];
                                                      switch(myFindType){
                                                                case "text":
                                                                          myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                                                          break;
                                                                case "grep":
                                                                          myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                                                          break;
                                                                case "glyph":
                                                                          myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                                                          break;
                                  } while(myFindChangeFile.eof == false);
                                  myFindChangeFile.close();
    function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
              //Reset the find/change preferences before each search.
              app.changeTextPreferences = NothingEnum.nothing;
              app.findTextPreferences = NothingEnum.nothing;
              var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
              myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
              myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
              app.doScript(myString, ScriptLanguage.javascript);
              myFoundItems = myObject.changeText();
              //Reset the find/change preferences after each search.
              app.changeTextPreferences = NothingEnum.nothing;
              app.findTextPreferences = NothingEnum.nothing;
    function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
              //Reset the find/change grep preferences before each search.
              app.changeGrepPreferences = NothingEnum.nothing;
              app.findGrepPreferences = NothingEnum.nothing;
              var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
              myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
              myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
              app.doScript(myString, ScriptLanguage.javascript);
              var myFoundItems = myObject.changeGrep();
              //Reset the find/change grep preferences after each search.
              app.changeGrepPreferences = NothingEnum.nothing;
              app.findGrepPreferences = NothingEnum.nothing;
    function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
              //Reset the find/change glyph preferences before each search.
              app.changeGlyphPreferences = NothingEnum.nothing;
              app.findGlyphPreferences = NothingEnum.nothing;
              var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
              myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
              myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
              app.doScript(myString, ScriptLanguage.javascript);
              var myFoundItems = myObject.changeGlyph();
              //Reset the find/change glyph preferences after each search.
              app.changeGlyphPreferences = NothingEnum.nothing;
              app.findGlyphPreferences = NothingEnum.nothing;
    function myFindFile(myFilePath){
              var myScriptFile = myGetScriptPath();
              var myScriptFile = File(myScriptFile);
              var myScriptFolder = myScriptFile.path;
              myFilePath = myScriptFolder + myFilePath;
              if(File(myFilePath).exists == false){
                        //Display a dialog.
                        myFilePath = File.openDialog("Choose the file containing your find/change list");
              return myFilePath;
    function myGetScriptPath(){
              try{
                        myFile = app.activeScript;
              catch(myError){
                        myFile = myError.fileName;
              return myFile;
    This is a very useful and easy to maintain script which even people who cant write scripts (but know how to use regex) can do complex search replace mass replacements.
    Would love to find something like this for FrameMaker 12 (as i can't write scripts myself).
    regards
    daniel

    I have visited that site. The first item in the external link says: "You can also configure Firefox to automatically search for text when you type any characters outside of a text field. When typing in a text field these characters should show up in the text field and not trigger the Quick Find bar. "
    What I am looking for is the exact opposite. Once my first search is entered in the text box, and the info comes back, I want to start typing the next symbol, and have it automatically show up in the text box, not the Quick Find box. That is how it was working up until a couple of months ago.

  • Applying Bolds and Italics while doing a Find/Replace on Data Merged content

    Hi,
    Wonder if you kind knowledgeable folks can help me with a Find/Replace question.
    I am doing a data merge of a book contents into indesign, where my data merge file is a straightforward text csv file which is tab delimited. I have two (almost similar) things I would like to do to specific parts of the text but don't know how to achieve this. 
    -  Firstly, I would like to preserve words/sentences with an 'italic' form but this is obviously lost in a csv file.  Is there anyway I can mark these words in order that a find/replace can make this word italics.  Im hoping there is a solution which resembles something like this;
    eg.  Book content is "The Word Italic needs to be adjusted".
    Original content is amended to be "The Word $Italic$ needs to be adjusted", so that a dollar sign encapsulates the word to be made Italic.
    Then I am able to data merge the csv file and somehow do a find/replace of words/sentences which are encapsulated by the dollar sign.  Thus, doing a find/replace of all words/sentences which satisfy this condition and then apply italics to all words between the dollar signs.
    - My other issue is I am using the '|' character in my text to determine the paragraph seperators.  I then do a find/replace after importing the text to replace all instances of '|' to the paragraph seperator (a kind of $ symbol, a representative character from the pop-up menu to the right of the Change To box). This works fine, but I'd like to make the paragraph seperator to be a BOLD format so that it can distinguish better the seperating sections of text.
    But this is different from my 'italics' issue above since I am trying to apply a BOLD format to the 'Change to' character, rather than something which exists in my original csv.
    Hope I make sense but I'd be happy to provide screenshots etc (when I get home )
    Best Rgds
    L

    two solutions.
    for the italic solution, i'd say the OP answered his own question with one exception - don't use dollar symbols, instead use = or another character which isn't reserved by GREP.
    the solution i would use for italics would be a GREP search once the merge is complete. have a look at the picture to see what i've done.
    the second solution: GREP styles.
    this assumes that the text will have a paragraph style assigned to it. make a character style called BOLD and within that style, the only thing to change is within basic character formats, make the font style bold. could even make the character another colour such as cyan so it is more easily idenfiable.
    next, go to the paragraph style options, go to GREP styles and match the following screengrab
    the advantage with a GREP style is that once the pipe symbol (|) is replaced, its bold GREP style character formatting is lost; and it means less post processing and no need for a second search of the text - it's all live.

  • TextEdit - Save preset for Find & Replace?

    Hey, all!
    Quick question... is there any way to save a preset for a Find & Replace function in the native TextEdit app in Mac OS?  I do a routine F&R using a long "Insert Pattern" (I haven't had time to learn Regular Expressions yet in order to use another app)... I'd love to be able to just do a quick F&R on a text file instead of having to build the string every time.
    Possible?
    Thanks!
    -=R=-

    thnx Tom - yes, all the text is there, editable and I can add new text to it and save. But I can't search it using Find, trying unique words I see right there in the first few paragraphs atop the file. Then tried 'and' which only found two in the whole large file, embedded within a block of what I guess are formatting characters also bunched up at the bottom of the file below my original text.
    Oops, I just realized now that this file is not actually an RTF, its a Word 97 .doc -- which either means I converted it at some point in TextEdit, or its the original .doc file I started long ago with my ancient Microsoft Word that I used before going to Mavericks (was able to use Word in Snow Leopard but is no longer supported in Mavericks, I think its referred to as a 'PowerPC' application.) 
    What should I do? Would converting it to an RTF file help, if so how do I do that?
    thanks!
    Randy

Maybe you are looking for