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.

Similar Messages

  • [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.

  • Replace part of a string

    I want to replace a part of a string value with another in table column(VARCHAR). For example \\server01\data\doc\123.eps with \\server02\data\doc\123.eps . How to replace the server01 part with server02?

    Use REPLACE.
    Cheers, APC
    SQL> select replace('\\server01\data\doc\123.eps', 'server01', 'server02')
      2  from dual
      3  /
    REPLACE('\\SERVER01\DATA\DO
    \\server02\data\doc\123.eps
    SQL>

  • How to replace part of a String with another String :s ?

    Got a String
    " Team_1/Team_2/Team_3/ "
    And I want to be able to rename part of the string (they are seperated by '/'), for example I want to rename "Team_3" to "Team C", and "Team_1" to "Team A" while retaining the '/' character how would I do this?
    I have tried using String.replace(oldValue, newValue); but this doesnt work, any ideas?

    What do you mean that it doesn't work? You do know that the method returns the modified string? The actual string that you invoke the method on is not altered.
    /Kaj

  • GREP search and replace: numbers and commas

    I have a list of numbers 1000, 15000, 250500, etc. and I would like to find only numbers that have 5 or more digitals, and insert a comma, like the following:
    1000 no change
    15000 replace with 15,000
    250500 replace with 250,500
    TIA

    One note, the replace patterns in ID need to use $, so that would be $1,$2 - otherwise I think that will work fine.
    You can also use curly brackets to indicate the number of possible occurrences of a pattern you're looking for.
    (\s\d{1,3})(\d{3}\s)
    Means find a space, 1 to 3 digits followed by 3 more digits and another space.
    One little note, if you were to put a bunch of number separated by single spaces in a string, this would skip alternate ones, because the trailing space of one number would be considered part of the find pattern for that match, and so would not be available as the leading space of the next number. (That may be very badly phrased, sorry.) In that case I think you'd have to break those spaces out to lookaheads/lookbehinds, where you include them in the find logic without making them part of the matched string. (Which may have made this response even less intelligible, but are at least terms to look at in the documentation.)

  • Search and replace characters in a string

    I am very new to Sharepoint and need your help.  I have set up a calculated column in a sharepoint list that combines a IT release number to its Release title.  The list is set to appear on a calendar plus web part.  The idea is to show
    the title and release number of all deployments going to the field on a particular day.  The issue is that the release number has a bunch of zero's in it that I do not need to be displayed.  For example a release number could be "RND000000123456". 
    I need to parse out "D000000" so only "RN123456" along with its title show up on the calendar.  Please help!!

    Go here and search for "Remove characters":
    http://msdn.microsoft.com/en-us/library/office/bb862071(v=office.14).aspx
    From that page:
    Remove characters from text
    To remove characters from text, use the LEN, LEFT, and RIGHT functions.
    Column1
    Formula
    Description (possible result)
    Vitamin A
    =LEFT([Column1],LEN([Column1])-2)
    Returns 7 (9-2) characters, starting from left (Vitamin)
    Vitamin B1
    =RIGHT([Column1], LEN([Column1])-8)
    Returns 2 (10-8) characters, starting from right (B1)
    You could also try the REPLACE function:
    http://office.microsoft.com/en-us/windows-sharepoint-services-help/replace-function-HA001161055.aspx
    Brandon Atkinson
    Blog: http://sharepointbrandon.com

  • Find & replace part of a string in Numbers using do shell script in AppleScript

    Hello,
    I would like to set a search-pattern with a wildcard in Applescript to find - for example - the pattern 'Table 1::$*$4' for use in a 'Search & Replace script'
    The dollar signs '$' seem to be a bit of problem (refers to fixed values in Numbers & to variables in Shell ...)
    Could anyone hand me a solution to this problem?
    The end-goal - for now - would be to change the reference to a row-number in a lot of cells (number '4' in the pattern above should finally be replaced by 5, 6, 7, ...)
    Thx.

    Hi,
    Here's how to do that:
    try
        tell application "Numbers" to tell front document to tell active sheet
            tell (first table whose selection range's class is range)
                set sr to selection range
                set f to text returned of (display dialog "Find this in selected cells in Numbers " default answer "" with title "Find-Replace Step 1" buttons {"Cancel", "Next"})
                if f = "" then return
                set r to text returned of (display dialog "Replace '" & f & "' with " default answer f with title "Find-Replace Step 2")
                set {f, r} to my escapeForSED(f, r) -- escape some chars, create back reference for sed
                set tc to count cells of sr
                tell sr to repeat with i from 1 to tc
                    tell (cell i) to try
                        set oVal to formula
                        if oVal is not missing value then set value to (my find_replace(oVal, f, r))
                    end try
                end repeat
            end tell
        end tell
    on error number n
        if n = -128 then return
        display dialog "Did you select cells?" buttons {"cancel"} with title "Oops!"
    end try
    on find_replace(t, f, r)
        do shell script "/usr/bin/sed 's~" & f & "~" & r & "~g' <<< " & (quoted form of t)
    end find_replace
    on escapeForSED(f, r)
        set tid to text item delimiters
        set text item delimiters to "*" -- the wildcard 
        set tc1 to count (text items of f)
        set tc2 to count (text items of r)
        set text item delimiters to tid
        if (tc1 - tc2) < 0 then
            display alert "The number of wildcard in the replacement string must be equal or less than the number of wildcard in the search string."
            error -128
        end if
        -- escape search string, and create back reference for each wildcard (the wildcard is a dot in sed) --> \\(.\\)
        set f to do shell script "/usr/bin/sed -e 's/[]~$.^|[]/\\\\&/g;s/\\*/\\\\(.\\\\)/g' <<<" & quoted form of f
        -- escape the replacement string, Perl replace wildcard by two backslash and an incremented integer, to get  the back reference --> \\1 \\2
        return {f, (do shell script "/usr/bin/sed -e 's/[]~$.^|[]/\\\\&/g' | /usr/bin/perl -pe '$n=1;s/\\*/\"\\\\\" . $n++/ge'<<<" & (quoted form of r))}
    end escapeForSED
    For what you want to do, you must have the wildcard in the same position in both string. --> find "Table 1::$*$3", replace "Table 1::$*$4"
    Important, you can use no wildcard in both (the search string and the replacement string) or you can use any wildcard in the search string with no wildcard in the replacement string).
    But, the number of wildcard in the replacement string must be equal or less than the number of wildcard in the search string.

  • 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.

  • Search and replace string formatting

    Hi,
    I am trying to do a search and replace formatting of a string.
    In the example I am looking for string "PASSED" but it must also start with usbflash and some number + PASSED.
    I can't get the format to have a number from 1-99. The number of replacements should add up to 6 in this case. I have tried with \d for any number, and I also tried [1-99].
    Solved!
    Go to Solution.

    Right click on the Search And Replace String function.  There is an option to use Regular Expressions.  Then give this a try.
    EDIT: You will need to set the Replace All input to TRUE.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Match Pattern.png ‏12 KB

  • Lua function to replace metatags in a string?

    (Maybe this is a recipe request for the new cookbook site.)
    I'd like a function that, given a string and a LrPhoto, will search and replace tags in the string with metadata from the photo. So, given a string 'The title of this photo is {{title}}', it would return a string where {{title}} has been replaced with the LrPhoto.getRawMetadata('title') (or maybe getFormattedMetadata). I'm sure it's been written more than once. Is there one out there to be shared before I write my own?
    db

    I spent the time on this myself and don't know why I bothered asking, it was so simple. Here's what I did. First, a general-purpose function to replace any token in a string with values from a table:
    -- replace any string of characters in a string that are surrounded by curly
    -- braces (e.g. {foo}) with the value in the table corresponding to 'foo'.
    -- will replace all tokens in braces if there are more than one
    function DFB.replaceTokens( tokenTable, str )
        return str:gsub( '{(.-)}', function( token ) return tokenTable[token] end )
    end
    Then, if you want to do this with a photo's metadata, just pass the table that's returned from getRaw/FormattedMetadata:
    line = DFB.replaceTokens(  photo:getFormattedMetadata( nil ) , line )
    So if line starts out with "my caption is {caption}" and the photo's caption is 'My Photo Caption', the result is "my caption is My Photo Caption".
    I use this in a simple templating system that reads an HTML template from a file and does this for each line as it reads/writes it. Works well.

  • GREP: date/time search and replace

    Hi everybody,
    I frequently import XML files to InDesign. The XML structure always contains the following information among others:
    start date
    start time
    end date
    end time
    For example, it looks like this:
    21.08.2013
    09:00
    25.08.2013
    18:00
    Now I need to re-arrange these fields in one row, just like this:
    21.08.2013, 09:00 - 25.08.2013, 18:00
    I already found out how to do this via GREP, but I need to go one step further:
    If "start date" and "end date" are the same (for example both are "21.08.2013"), I would like to skip the "end date" in the output. It should look like this:
    21.08.2013, 09:00 - 18:00
    Is there a way to do this via GREP?
    Thanks in advance!

    This will do it
    Trevor
    // By Trevor http://forums.adobe.com/thread/1261365?tstart=0
    app.doScript("formatDates ()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "GREP: date/time search and replace");
    function formatDates ()
            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.findWhat = "\\d\\d\.\\d\\d\.\\d\\d\\d\\d\r\\d\\d:\\d\\d\r\\d\\d\.\\d\\d\.\\d\\d\\d\\d\r(?=\\d\\d:\\d\\d\r)";
            var doc = app.activeDocument,
                  dateFinds = doc.findGrep(),
                  l = dateFinds.length, dates;
            while (l--)
                    app.findGrepPreferences.findWhat = "(\\d\\d\.\\d\\d\.\\d\\d\\d\\d)";
                    dates = dateFinds[l].findGrep();
                    app.findGrepPreferences.findWhat = "(\\d\\d\.\\d\\d\.\\d\\d\\d\\d)\r(\\d\\d:\\d\\d)\r(\\d\\d\.\\d\\d\.\\d\\d\\d\\d)\r";
                    if (dates[0].contents == dates[1].contents) app.changeGrepPreferences.changeTo = "$1 $2 - ";
                    else app.changeGrepPreferences.changeTo = "$1 $2 - $3 ";
                    dateFinds[l].changeGrep();

  • 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.

  • Case insensitive search and replace using ASP and Oracle database

    I am interested in providing a case insensitive search and replace query in a Active server page. At present data is collected from a html form which passes the text values to a ASP page. The ASP page runs a search (select query) to find if the data is already in the Oracle database, if it isn't the ASP page runs sql (INSERT) to insert the record, if not the page returns a form indicating that the record already exists. At present we can convert the case of new records using the VB UCase() function. But can't do a insensitive search with the existing records. *The Query must be able to utilize ASP variables.
    Any help would be much appreciated.
    David Cheryk
    null

    I can't check your script right now since I'm not on Mac. I recommend you to use FindChangeByList script for CS4 instead (it works with CS3): http://forums.adobe.com/servlet/JiveServlet/download/2080627-12695/FindChangeByListCS4.zip together with Martin Fisher's: http://www.kasyan.ho.com.ua/downloads/RecordFindChange_CS3_Kas.zip
    Use this script to record settings from Text and GREP tabs, then copy and paste them into FindChandgeList.txt file.
    Or, optionally you can use this script: http://www.kasyan.ho.com.ua/find_change_by_queries.html.
    Kasyan

  • How to get numeric result from 'search and replace' string function

    hii
    i am using search and replace function to get output.my output is of form ' *X0123.3 ' .here i am replacing the term *X01 with space because i need only 23.3 as a result.but i am unable to get that out in the output indicator.i used lot of functions like string to number and so on but i am getting output as zero .can you please suggest me wt to do.i am attaching a copy of my file.
    Attachments:
    Untitled 1.vi ‏25 KB

    Your problem is the fact that you are converting it to an integer, thus loosing the fractional part. You need to use "Fract/Exp String To Number" instead and create a DBL so yor data is 23.3 instead of 23.
    You also don't need to manipulate the string if the initial part is of constant lenght. Just use the offset input as in the figure below.
    Message Edited by altenbach on 07-31-2006 07:02 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ToDBL.png ‏2 KB

  • Search and Replace String throwing the wrong error message with regexp?

    This came up in a LAVA thread, and I'm not sure if there's a bug here or not. When using Search and Replace string, and using a regular expression of [(G[b|i])], LabVIEW throws error -4622, "There is an unmatched parenthesis in a regular expression."  There are obviously no unmatched parenthesis in that expression, so it seems to me that the wrong error is being thrown. I'm just not sure if that's a syntactically valid regexp. The problem seems to be with nesting [ ]'s inside ( )'s inside [ ]'s. I've tried a couple of regexp resources on the Web, and one suggests it's valid, while the other seems to think it isn't.
    Message Edited by eaolson on 03-13-2007 10:33 AM
    Attachments:
    ATML_StandardUnit2.vi ‏10 KB
    regexp.png ‏5 KB

    adambrewster wrote:
    I think your regexp is invalid.
    In regexps, brackets are not the same as parentheses.  Parens are for grouping, while brackets are for matching one of a class of characters.  Brackets can not be nested.
    If the regexp is replaced with [G[bi]], there is no error, so it's not a matter of nested brackets. I couldn't find anything on the PCRE man page that forbids nested brackets specifically, but it makes sense.
    Your expression "[(G[bi])]", therefore parses as a character class which matches '(', 'G', '[', 'b', or 'i' followed by an unmatched paren, and an unmatched bracket.
    I don't believe that's the case. Replace the regexp with [(Gbi)], and the error goes away. So it's not a matter of the '(' being literal, and then encountering a ')' without a matching '('.
    daveTW wrote:
    what string exactly you want to replace? I think the round braces are not right in this case, since they mark partial matches which are given back by "match regular expression". But you don't want to extract parts of the string, you want to replace them (or delete, with empty <replace string>). So if you leave the outer [( ... )] then your RegEx means all strings with either "Gb" or "Gi".
    It's not my regular expression. A poster at LAVA was having problems with one of his (a truly frightening one), and this seemed to be the element that was causing the problem. I'm pretty sure that the originator of the regexp meant to use G(b|i), which seems like a complicated way of matching "Gb" or "Gi", if you ask me.

Maybe you are looking for