Replace the page to find number by matching the string

Hi all

Write the script (InDesign CS5) update the page number of the collection of the Keyterms end of this chapter. These keyterms inside this chapter applied with a character named "KT" style Here, I have collected text style applied all the "KT" with its page number appropriate by using the following code. The keyterms collection have the paragraph style "KTSET" and the page number character style "KTSET_PG". Between these two, there may be some em space or space en dash or space of Word. I just want to change these page instead of "000" number corresponding to its text (keyterms) appropriate. For example, autpatu 000 mmoloreetue must be autpatu mmoloreetue 2. I match these two strings and replace the single page number.

KeyTerm.png

var myDoc = app.activeDocument;
app.findTextPreferences = null;
app.findTextPreferences.appliedCharacterStyle = myDoc.characterStyles.item("KT");
var myResults = myDoc.findText();
var myFoundText = new Array;
for (var i = 0; i < myResults.length; i++)
{
    var r = getPage(myResults[i].characters[0]);
    myFoundText.push ([myResults[i].contents, r.name]);
}
alert(myFoundText)

function getPage (element)
{
    while (!(element instanceof Page || element instanceof Application))
    if (element instanceof Character)
    element = element.parentTextFrames[0].parentPage;
    else element = element.parent;
    if (element instanceof Page)
    return element;
    return null;
}

Any ideas or some suggession would be useful for me.

Thanks in advance.

Try this:

app.findGrepPreferences.findWhat = "\\b (" + myText.toLowerCase () + "\\s) 000".
app.changeGrepPreferences.changeTo = "$1" + myPage;

Tags: InDesign

Similar Questions

  • Search and replace the string formatting

    Hello

    I try to do a search and replace the formatting of a string.

    In the example, I'm looking for the string 'SUCCESSFUL', but it must also begin by usbflash and some number + PASSED.

    I can't get the format to have a number between 1 and 99. The number of replacements should add up to 6 in this case. I tried with \d for any number, and I also tried [1-99].

    Make a right-click on the function search and replace the string.  There is an option to use regular Expressions.  Then give it a try.

    EDIT: You need to set the entry replace all to TRUE.

  • How to replace the string "\" on json webservice?

    Hello

    I have problem with this json

    "{\"search_result\":[{\"name\":\"Mall Summarecon\",\"category\":\"BusinessEntity\",\"id\":\"1\"},{\"name\":\"Bamboo Dim Sum\",\"category\":\"BusinessEntity\",\"id\":\"2\"},{\"name\":\"Dimsum Ceker\",\"category\":\"Item\",\"id\":\"1\"}]}"
    

    I want to replace the string "\".

    the json are already working on my app via .cpp file

    I already add json.replace on my qml

    function simpleSearch(response){
            indicator.stop()
            model.clear()
            console.log("Response: "+response)
            var json = JSON.parse(response)
            json = json.replace('\\', ' ') // this is how the way i replace
            if (json == "[]")
                notFound.visible = true
    
            else
                model.append(json.search_result)
        }
    

    but still does not work

    is there a different way to replace it?

    Thank you

    Change your simpleSearchFinished as follows

    ....simpleSearchFinished()
    {
        QNetworkReply *reply = qobject_cast(sender());
        if (!reply->error()){
            QByteArray response = reply->readAll();
            response.replace("\\", "");
            if (response.startsWith("\"")){
                response.remove(0, 1);
            }
            if (response.endsWith("\"")){
                response.remove(response.length()-1, 1);
            }
            emit simpleSearchDone(response);
        }else{
            const int httpCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            qDebug() << "ErrorCode" << httpCode << endl << \
                    "ErrorString" << reply->errorString();
            emit error(httpCode, reply->errorString());
        }
        reply->deleteLater();
        manager->deleteLater();
    }
    

    and QML

    function simpleSearch(response){
        indicator.stop()
        model.clear()
        var json = JSON.parse(response)
        if (json){ // is VALID/PARSED
            model.append(json.search_result)
        }
    }
    

    As I wrote, it is not a good workaround solution. The best is to send VALID JSON string directly from your server. But it works

  • Replace the string value of table

    with cte as)

    Select val '123', 'abwec' double val1

    Union of all the

    Select "456" val, "mowerw" double val1

    Union of all the

    Select val '709', 'wkwere' double val1

    Union of all the

    Select val '078', 'awerwewerwreq' double val1

    )

    Select * from cte;

    -incoming string

    "asdasd123ewrwer@87w8eopiu456werwer@asdwer709@ewrwerewrwqqwezxder078 @..."

    need to replace like 'abwec' 123 and 456 as "mowerw" and 709 as wkwere and 078 as 'awerwewerwreq '.

    How to replace the string value of the string

    I'm going to the table which will have mapping information I need to see the incoming string and replace the appropriate value of the val to val1

    something like

    Of

    "asdasd123456werwer@asdwer709@ewrwerewrwqqwezxder078ewrwer@87w8eopiu @..."

    TO

    "asdasdabwecewrwer@87w8eopiumowerwwerwer@asdwerwkwere@ewrwerewrwqqwezxderawerwewerwreq@..."

    By using the TYPE clause.

    with cte as

    (

    Select val '123', 'abwec' double val1

    Union of all the

    Select "456" val, "mowerw" double val1

    Union of all the

    Select val '709', 'wkwere' double val1

    Union of all the

    Select val '078', 'awerwewerwreq' double val1

    ),

    input_tbl

    as

    (

    Select "asdasd123ewrwer@87w8eopiu456werwer@asdwer709@ewrwerewrwqqwezxder078 @..." input_str

    of the double

    )

    Select max (input_str) Dungeon (first order by desc NWR dense_rank) input_str

    de)

    Select rno, input_str

    de)

    Select rownum NWR

    val

    val1

    input_str

    count (*) over() cnt

    from cte

    Cross

    Join input_tbl

    )

    model

    dimension (NWR)

    measures (val, val1, cnt, CAST (input_str AS VARCHAR2 (4000)) input_str)

    (

    input_str [any] = replace (nvl (input_str [cv () - 1], input_str [cv ()]), val [cv ()], val1 [cv ()])

    )

    )

  • Find and replace the string function replaces line breaks when I only replaced spaces?

    I need to replace all instances of a space or a series of spaces to a line with commas (or tabs) multi string so I can throw in a worksheet.

    I use the regular expression [\s]+ and it works, but it is also to replace the end of lines (\r\n) too.

    How can I replace the spaces but leave the end of the lines intact?

    Right-click on the search string and to take '-' code display. Enter the space character (\s) correctly - you \\s right now.

  • Regex find number at end of string

    Hi guys,.

    I try to learn regex, but it's hard and I'm stuck to a simple task:

    Let's say I have this string:

    "C1".

    I would like to find what is the number to the end of the line. I can do with this regular expression ' [0-9] + $".

    Now if this chain was formed with a small error, say a character 'space' after the number:

    "C1".

    My regex would not '1 '.

    What should I change in my regex to find the last number in the string, even if it has an error?

    P.S. The string can contain several numbers, such as "C5_IND1". My regex must return '1 '.

    Use the look early.  I sounds like you want the last number which is not followed by another number:

    (\d+) (?!. * \d)

  • Replace the string with the formatted text

    Hello all - I'm back to my beloved project...

    I want to replace a string by a TextSelction (formatted text) and began with the famous feature of Jang FindAndReplaceString.
    Since my replacement comes from another document (sourceDoc), I edited to targetDoc activeDoc and introduced a second document (sourceDoc).
    The replacePara actually comes from a stone where he had been placed to avoid switch backwards between the documents in a book (where to find and replace) and source documents. In another function, I learned that information on the table requires the sourceDoc must remain open.

    • Of course, everything works fine until I want to insert the replacelement:
      erase line 26 is the string
    • Given that I do not insert a string, I skip lines 28 and 29 and try try line 30
    • On line 30 DocumentSource is Document object and replacePare object TextSelection. However, sourceDoc.replacePara is not set and
    • (as a result?) line 31 past the current contents of the Clipboard.

    Of course, there is a fog around me... and I need some sunshine.

    function FindAndReplacePara (targetDoc, findString, sourceDoc, replacePara, loopMax) {
      var tr = new TextRange();
      var restoreTR, frame = 0, loopCounter = 0, replacementCounter = 0;
      var findParams = new PropVals();
      var firstPgf = targetDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
      
      tr.beg.obj = tr.end.obj = firstPgf;             //  set up the starting text range as the very beginning
      tr.beg.offset = tr.end.offset = 0;              // of the flow. We'll move straight from beginning to end.
      trSaved = tr                                    // to come back after work
    
      findParams = AllocatePropVals(2);
      
      findParams[0].propIdent.num = Constants.FS_FindText;
      findParams[0].propVal.valType = Constants.FT_String;
      findParams[0].propVal.sval = findString;
      
      findParams[1].propIdent.num = Constants.FS_FindCustomizationFlags;
      findParams[1].propVal.valType = Constants.FT_Integer;
      findParams[1].propVal.ival = Constants.FF_FIND_CONSIDER_CASE;
    
      FA_errno = Constants.FE_Success;                // errno global, to be used to track the progress of the find and replace
      tr = targetDoc.Find(tr.beg, findParams);        // and do an initial find to get started.
      
      while(FA_errno === Constants.FE_Success && loopCounter++ < 2*loopMax) { //find and replace loop as long as we keep finding
        targetDoc.TextSelection = tr;                 // set up the text range to clear the original text
        targetDoc.Clear(0);                           // clear it
        
    //    targetDoc.AddText(tr.beg, replacePara);       // insert the new text at the original beginning of the text range
    //    tr.beg.offset += replacePara.length;          //  lets jimmy the text range in memory to place it directly after
        targetDoc.TextSelection = sourceDoc.replacePara;        // paste the whole replacement paragraph
        targetDoc.Paste (0);                          // <-- Current contents of clipboard is pasted !!!!
        if(FA_errno === Constants.FE_Success) {       // increment our return counter
          replacementCounter++;
        }
        FA_errno = Constants.FE_Success;              // ...  find the next instance. We'll reset FA_errno again just in case
        tr = targetDoc.Find(tr.beg, findParams);      // something screwy happened while we were replacing text.
      }
      targetDoc.ScrollToText(trSaved);                // we're done. Restore the document to it's original area of display
      return replacementCounter;
    } // --- end FindAndReplacePara
    

    Hi Klaus,

    Thanks for the explanation. I remember something like that GetTabRange of the way back. You have been quite patient and persistent with this project, indeed.

    So, as we are dealing with ranges of text here, I think that the only simple approach is to perform a copy and paste. There is no way to save a 'formatted' in a variable. The only super precise way would be to get a data structure of each text range TextItems in the sourceDoc, then meticulously recreate every element of the targetDoc. It would be very complicated, I think, so copy and paste seems the most logical. I wonder, though, if Miss me something, because I think that maybe you would have tried already so yes (?)

    In any case, I would do something like that, from line 30 of your original code sample (code untested here):

    App. ActiveDoc = sourceDoc;

    sourceDoc.TextSelection = replacePara;

    sourceDoc.Copy (0);

    App. ActiveDoc = targetDoc;

    targetDoc.Paste (0);

    ... etc.

    Does make sense, or am I barking the wrong tree, as they say?

    Russ

  • Replace the strings inside SWF's AS2/3

    There are, on some Board there are a few foreign flashes that predate the internet and effectively anonymous pertaining to the creator, if someone used a program to get the strings in the SWF file (programmed in AS3), machine to translate them and put back them.

    Deal is a machine translation. It's funny, but it's still wrong and I would like to do a good job of translating.

    So to get to the point, I would like to know where I might be able to find a program that can get the strings inside a SWF file that is programmed in AS2 or AS3, show them to me and I would like to replace them with custom text. The reason why I want to do it this way is that I must not decompile SWF. Decompile a SWF is bound to generate errors and I could not have certain fonts inside so I also have little to do with the opening of the thing I can.

    I tried a few solutions, including FLASM (only works on AS2) and others don't bother naming such that they are no longer capable of displaying the AS3 code and not edit or replacement of classes.

    I'm not 'try' anything.  I inform you of your options.

    If you do not find the source files and that you can not use a decompiler, you cannot change the source code.

  • Replace the string in BPEL

    Hey all,.

    I need to replace the & with a + since the & just breaks the bpel process. Any ideas on how to make a replacement string to find all the the & and replace it with the +, I looked in the transformation and the entitlement activity, but did not find all the functions to help me with this.

    Any help would be appreciated.

    Thank you

    You can create an XSL template for string replacements, see the link given below:
    http://geekswithblogs.NET/Erik/archive/2008/04/01/120915.aspx

    If you are familiar with Java you can add a Java embedding activity and string replacement using the method of the replacement of the java.lang.String class.

    Diakité
    http://SOA-HOWTO.blogspot.com

  • Search and replace the string in a column

    Hello

    In the table the data stored with "" (double quotes), I need to remove these quotes please suggest me how to remove


    Select the address of TECH_SOURCING_EMPLOYEE_DETAILS

    "No. 12/32"-> data recorded in this format in the table. I need to remove the double quotes


    Thank you
    Sudhir

    Hello

    UPDATE to modify existing rows in a table
    REPLACE to delete a given sub - a to a string.

    UPDATE     tech_sourcing_employee_details
    SET     address     = REPLACE (address, '"')
    WHERE     INSTR (address, '"')         > 0          -- Maybe
    ;
    

    This will remove all the quotes of the address.
    If you want to remove the quotes only from the beginning and the end of the string, then use TRIM instead of REPLACE:

    UPDATE     tech_sourcing_employee_details
    SET     address     = TRIM ('"' FROM address)
    WHERE     INSTR (address, '"')         > 0          -- Maybe
    ;
    

    The WHERE clause is only for effectiveness.
    So, whenever the column contains quotes, of the double quotation mark is always the first character in the string, then you can change the WHERE clause to:

    WHERE     address  LIKE '"%'
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    
  • Search and replace the string from a result

    Hi all
    I want to search a "("or ")" of the chain and all want the string before replacing "(" with a blank space...


    for example
    If the result comes like this
    name
    12 #122 (on the opening balance)
    I want the result as

    name
    on the opening balance)

    means
    12 #122 is replaced by "" how


    thanking you
    Gaurav Sontakke

    Like this?

    WITH t AS
         (SELECT '10 #10 (moving standard to msp1004)' str
            FROM DUAL
          UNION ALL
          SELECT '13208 #0' str
            FROM DUAL
          UNION ALL
          SELECT '2002-02-22 #10' str
            FROM DUAL)
    SELECT SUBSTR (str, 1, INSTR (str, '#') - 1)
      FROM t
    
  • Replace the string on a specific line

    Hi everyone thanks in advance for your time.

    I have almost finished a project, (a software to manage the booking of hotel rooms and a database of passengers).

    I made a function that writes a .txt file a cluster with some personal information string type fields, each field is separated by tabs, and each client separated by a line news.

    Example: name address phone etc.

    Robert xxxxxx yyyyyyy

    Patrick xxxxxx yyyyyyy

    Mila xxxxxx yyyyyyy

    Now I don't know how I can do to perform a search by name and to be able to change each field.

    Example:

    If I search for Patrick, I want to be able to change the address or phone number or any other field.

    I know how to search in a text file, until I reach the word, but I don't find a way to change the field and write once again the information in the same file in the same line of origin.

    Any contribution will be great! Thanks again.


  • Replace the string

    Hi all

    I need like below.  FONT-FAMILY string twice, repeat with the lowercase and uppercase, highlited blue color.

    What ever after FONT FAMILY contains data must replace it with our new channel.

    Select ' < P style = "MARGIN-BOTTOM: 0pt" > < SPAN style ="FONT-FAMILY: arial, calibri" data-mce-style ="-font family: arial, black, Vanguard;" > < SPAN style = "" FONT-SIZE: 14pt "data-mce-style =" font size: 14pt; "> < SPAN style =" "COLOR: #ff0000 ' data-mce-style =" color: #ff0000; ' > it is arial black14pt </span > < / SPAN > < / SPAN > < / p > '

    of the double

    Power required:

    < P style = "MARGIN-BOTTOM: 0pt" > < SPAN style ="FONT-FAMILY: Calibri" data-mce-style ="font family: Calibri;" > < SPAN style = "" FONT-SIZE: 12pt "data-mce-style =" do-size: 12pt; "> < SPAN style =" "COLOR: #ff0000 ' data-mce-style =" color: #ff0000; "> it is arial black14pt </span > < / SPAN > < / SPAN > < / p >

    Like this?

    SQL > ed
    A written file afiedt.buf

    1 with t as (select"


    = "" color: #ff0000; "> it is arial black14pt"

    "as double txt).
    2  --
    3 end of test data
    4  --
    5 Select regexp_replace (txt, "([Ff][Oo][Nn][Tt]-[Ff][Aa][Mm][Ii][Ll][Yy]:).*?)" ",' \1Calibri" ') as txt
    6 * t
    SQL > /.

    TXT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    It is arial black14pt
    / SPAN >

  • How to write good model to replace the string after a static string?

    Select regexp_replace ("Do replace not CONSTANT" VAR_123 "needs to be replaced", "CONSTANT" [A-Z0-9] ',' CONSTANT "REPLACE") twice;

    The output is:
    Does not replace CONSTANT 'REPLACEAR_123' SHOULD be replaced

    Output available is:
    Does not replace CONSTANT 'REPLACE' SHOULD be replaced


    What is the right model to solve my problem?

    Assistance is needed.


    Concerning

    possible alternatives

    /* replace everthing in between "" */
    select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced '
                        , '"([A-Z0-9_]*)"' ,'"REPLACE"')
    from dual;
    
    Do not replace CONSTANT "REPLACE" should be replaced 
    
    /* replace UPPER letters, Numbers and Underscore after keyword CONSTANT an in between "" */
    select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced '
                        , '(CONSTANT) "([A-Z0-9_]*)"' ,'\1 "REPLACE"')
    from dual;
    
    Do not replace CONSTANT "REPLACE" should be replaced 
    
    /* replace alphanumerica values including underscore after keyword CONSTANT an in between "" */
    
    select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced '
                        , '(CONSTANT) "([[:alnum:]_]*)"' ,'\1 "REPLACE"')
    from dual;
    

    One of the problems is that did ' t take you into account how the underscore character '_' is recognized.

  • Replace the string, each value should double quotes around it

    How can I replace this basic string with double quotes around each value?

    dog, cat, john, mark

    I would like to:

    'dog', 'cat', 'john', 'brand '.

    Thank you

    -weStsIdE

    Hello

    I answered my own question. Well nice for someone else. The function ListQualify will insert what you need before and after each element of individual list.

    Actually powerful enough that you can just insert double quotation marks, for example around channels and leave intact numeric values.

    -weStSidE

Maybe you are looking for