7 Replies Latest reply on Apr 8, 2010 5:10 AM by [Jongware]

    FindChangeByList bug?

    emspaces

      Hello,

       

      I'm using grep searches in the FindChangeByList script and this one line doesn't seem to work for some reason :

       

      grep {findWhat:"(?<=\w)[!?;»%$¢°]"} {changeTo:"~<$0"}

       

      But if I copy paste the info in the normal Grep Find / Change dialog, it works.

      I'm trying to find any !?;»%$¢° characters preceded by a letter or a number and add a thin space before it.

       

      {findWhat:"\s(?=[!?;»%$¢°])"} {changeTo:"~<"}

      I use this line to change any existing space preceding those signs and convert it to a thin space and it works.

       

      Any ideas? Are there differences in the way I should type my expressions in the find/change grep dialog vs. adding them to the FindChangeByList script? Or maybe the way I typed my expressions is not efficient, I'm quite new to this!

       

      Thank you for your time,

      Emilie

        • 1. Re: FindChangeByList bug?
          Kasyan Servetsky Level 5

          Check out Martin Fisher's Record Find Change script.

           

          Kasyan

          1 person found this helpful
          • 2. Re: FindChangeByList bug?
            emspaces Level 1

            Oh! It's working now thank you... it changed from this :

             

            grep {findWhat:"(?<=\w)[!?;»%$¢°]"} {changeTo:"~<$0"}

             

            grep {findWhat:"(?<=\\w)[!?;»%$¢°]"} {changeTo:"~<$0"}

             

            So it added a  \ before \w... But are you supposed to escape wildcards? I thought this only applied to characters like brackets and such?

             

            Emilie

            • 3. Re: FindChangeByList bug?
              [Jongware] Most Valuable Participant

              No (and yes), but remember this is not entered 'straight into indesign'. It's going to end up inside a script -- and the backslash is also a special character in Javascript. What you entered is not an "InDesign GREP expression", but rather a Javascript string that ought to be inspected and executed by a command in another program (that would be InDesign, in this case).

               

              If you enter "\t" into a Javascript, InDesign will not see a backslash tee when running the script, it will see a tab character. That's not a problem if you did mean to have a tab character somewhere, but it doesn't work with '\w' and almost any other backslash-code. So to get a literal single backslash into ID, enter two.

              • 4. Re: FindChangeByList bug?
                emspaces Level 1

                I think I understand (but my head hurts a little...) ;-)

                Is there a list somewhere of these wildcards (or other characters) that need to be escaped twice when used in Javascript and only once in GREP?

                 

                Thank you for the insight!

                Emilie

                • 5. Re: FindChangeByList bug?
                  Peter Kahrel Adobe Community Professional & MVP

                  It's not wildcards that need to be escaped, it's the backslash. So wherever you type a single backslash in the interface, you type two in Javascript. No exceptions.

                   

                  Peter

                  1 person found this helpful
                  • 6. Re: FindChangeByList bug?
                    emspaces Level 1

                    So if I wanted to search for a slash in ID, I would need to espace it by typing another one \\ and if I were to do this in Javascript, do I need to type three \\\ to escape just the beginning of the thing or four \\\\ to escape both of them?

                     

                    I guess learning some Javascript would help :-)

                     

                    Emilie

                    • 7. Re: FindChangeByList bug?
                      [Jongware] Most Valuable Participant
                      So if I wanted to search for a slash in ID, I would need to espace it by typing another one \\

                       

                      Yes -- but only in GREP. In the regular Text Search box, it's not a "special" character. (But the ^ is, and to search for a ^ you have to insert two.)

                       

                      and if I were to do this in Javascript, do I need to type three \\\ to escape just the beginning of the thing or four \\\\ to escape both of them?

                       

                      Four Each 'escape' character only acts on the character immediately after it. So "\\\Hello" would be translated to one backslash, followed by a "\H" code (whatever that may be), followed by "ello".

                       

                      I guess learning some Javascript would help :-)

                       

                      This -- adjusting the FindChangeList file -- is as far as a lot of people dare to go. You already crossed an invisible border by asking, "what goes wrong here?" where others would simply have shrugged it off as "it dont work" and do it manually instead.

                       

                      Think of something you might want to script, give it a try (there are lots of good beginners' JS web pages) and post here if you get stuck!