31 Replies Latest reply on Apr 28, 2014 8:23 PM by wideEyedPupil

    GREP question

    Radek Bartunek

      Dear all,

       

      can anyone of you, GREP specialist, explain me the following behavior? I am not a GREP guru, but I understand the principles and I was able the create my own simple GREP question in InDesign (using CS6 on Win7), which worked perfectly until yesterday... It replaces space after one-sign words (prepositions, conjuctions) with non-breaking space:

       

      Find: (\<\(?)([\l\u])(\s)

       

      Replace: $1$2~S

       

      I must repeat that I have used it for last two years and it have worked. But, starting on yesterday the replacing does not work correctly. Can I ask for explanation and solution of this?

       

      GREP.jpg

       

      Radek

        • 1. Re: GREP question
          Peter Spier Most Valuable Participant (Moderator)

          Seems to be working here. Try trashing the prefs. See Replace Your Preferences

          • 2. Re: GREP question
            pixxxel schubser Level 5

            I would also tap that the preferences are damaged.

             

            But the Grep is already too complicated.

            IMHO better is:

            find:

            \<([\l\u])\s

            replace with:

            $1~S

            • 3. Re: GREP question
              Radek Bartunek Level 1

              Thank you, Peter, but still does not work... I have tried both ways to replace preferences, but unsuccessfully.

               

              Radek

              • 4. Re: GREP question
                Peter Spier Most Valuable Participant (Moderator)

                pixxxel schubser wrote:

                 

                I would also tap that the preferences are damaged.

                 

                But the Grep is already too complicated.

                IMHO better is:

                find:

                \<([\l\u])\s

                replace with:

                $1~S

                It finds a single character word, or a single character word preceded by an opening parenthesis, so it would match both A boy and his dog and (a boy and his dog). It needs the GREP as written and $1$2 to replace that. It won't match a single character preceded by a quote mark, though, so no match for "A boy and his dog."

                • 5. Re: GREP question
                  Radek Bartunek Level 1

                  Yes, of course, this version is simplier. But I work with texts where combinations like "...(a word word...)" often occur and in my language must not "(a" stand on the end of the line. Therefore I needed to construct more complicated GREP.

                   

                  Radek

                  • 6. Re: GREP question
                    Peter Spier Most Valuable Participant (Moderator)

                    Radek Bartunek wrote:

                     

                    Thank you, Peter, but still does not work... I have tried both ways to replace preferences, but unsuccessfully.

                     

                    Radek

                    Then I'm not sure what's wrong.

                     

                    \<(\(?)([\l\u])(\s) seems to work the same way here. \<([(~{~[]?)([\l\u])(\s) would match with opening quotes, too.

                    • 7. Re: GREP question
                      Radek Bartunek Level 1

                      Failed again...

                       

                      GREP.jpg

                      • 8. Re: GREP question
                        Peter Spier Most Valuable Participant (Moderator)

                        It occurs to me that this might work better as a GREP style in your paragraph styles than using Find/Change since it would be automatic. You can do that by creating a character style whose only attribute is No Break and apply that using the query.

                        • 9. Re: GREP question
                          Obi-wan Kenobi Adobe Community Professional

                          Hi,

                           

                          Peter is right: use a grep style with your own code and a char style (including a no-break option).

                           

                          That does not explain why I obtain the same result than Radek when the code is used with a grep search !? 

                          • 10. Re: GREP question
                            Radek Bartunek Level 1

                            First of all, it does not explain, why my GREP has worked for two years and all at once it does not work properly. :-(

                             

                            Radek

                            • 11. Re: GREP question
                              Obi-wan Kenobi Adobe Community Professional

                              Aha! Radek, you're right!

                               

                              Why is ID so vicious with us?

                              • 12. Re: GREP question
                                Peter Spier Most Valuable Participant (Moderator)

                                It would probably work as a find/change as well if instread of replacing the space with a non-breaking space you apply the No Break attribute as change formatting and leave the text itself as-is. There's actually an advantage to doing it with No Break. The character inserted using ~S is fixed width, where No Break would keep your existing flexible width space in justified text.

                                • 13. Re: GREP question
                                  pixxxel schubser Level 5

                                  Peter Spier wrote:

                                   

                                  It finds a single character word, or a single character word preceded by an opening parenthesis, so it would match both A boy and his dog and (a boy and his dog). It needs the GREP as written and $1$2 to replace that. It won't match a single character preceded by a quote mark, though, so no match for "A boy and his dog."

                                   

                                  Sorry, but I didn't understand you.

                                   

                                  Please see the Grep by Radek Bartunek as style:

                                  SingleSignYours.png

                                   

                                  And now see the grep that I posted before:

                                  SingleSignMe.png

                                  There is no difference???

                                  What do you mean? And sorry, my english is to bad for many things and the translators are often no great help for me.

                                  • 14. Re: GREP question
                                    Obi-wan Kenobi Adobe Community Professional

                                    Obviously, I prefer your code and I would have written like you (I like it!). The result is the same with a grep style.

                                     

                                    The big difference is that yours works in a grep research !! Not that of Radek.

                                     

                                    Can you tell me Why?

                                    • 15. Re: GREP question
                                      Radek Bartunek Level 1

                                      Thank you, Peter, for all your suggestions...

                                       

                                      Nevertheless I must repeat: my GREP (complicated or not) has worked for many months without problems. Therefore I suppose there was not any error in syntax of this regular expression, but... It has stopped working now, all at once - and I like to know why.

                                       

                                      Radek

                                      • 16. Re: GREP question
                                        Obi-wan Kenobi Adobe Community Professional

                                        Me too…

                                        • 17. Re: GREP question
                                          [Jongware] Most Valuable Participant

                                          Radek Bartunek wrote:

                                           

                                          [..] My GREP (complicated or not) has worked for many months without problems. Therefore I suppose there was not any error in syntax of this regular expression, but... It has stopped working now, all at once - and I like to know why.

                                           

                                          Me as well ...

                                           

                                          Your GREP Find expression is syntactically correct.

                                           

                                          (      Begin Group #1
                                               \<      Beginning of a word
                                               \(?      Literal opening parenthesis; may occur once, or not at all
                                          )      End Group #1
                                          (      Begin Group #2
                                               [      Inclusion: any character in this group
                                                    \l      Any lowercase character (a..z)
                                                    \u      Any uppercase character (A..Z)
                                               ]      End Inclusion Group
                                          )      End Group #2
                                          (      Begin Group #3
                                               \s      Any white space
                                          )      End Group #3
                                          
                                          
                                           (1 \< \( ? 1) (2 [ \l \u ] 2) (3 \s 3)

                                           

                                          In the Replace field, you substitute Group #1 with itself, as well as Group #2, and discard Group #3 -- the space. That is also done correct: '$1' is for Group #1, '$2' for Group #2 (and so on).

                                           

                                          If you use '$2' in the Replace field but there is no Group #2 in the Find field, then you get the literal text '$2'. But that is not the case here.

                                           

                                          Did you recently update your InDesign, around the time this stopped working correctly?

                                          • 18. Re: GREP question
                                            Peter Spier Most Valuable Participant (Moderator)

                                            Well apparently I've misunderstood what is identified as the beginning of a word. \<. will  find the 'a' in (a boy and his dog), not the the '(', so you are correct, the entire group to cover panetheses and quotes is completely unnecessary. Something new learned today. Thanks.

                                            • 19. Re: GREP question
                                              Obi-wan Kenobi Adobe Community Professional

                                              Hi Jongware,

                                               

                                              Unless I am mistaken, there's a problem with the first part:  (\<\(?)

                                               

                                              If you have:  (\()([\l\u])(\s)

                                              No problem.

                                               

                                              For me, with ID CC, (\<\(?) does not capture anything!

                                               

                                              Moreover, this writing is of no interest.

                                               

                                              \<([\l\u])\s (from pixxxel schubser) is much more interesting.

                                               

                                              So, we still have the same problem. 

                                               

                                              BUT: If you change ALL, the regex works well!!!!!!!!!!!!!!

                                              • 20. Re: GREP question
                                                Obi-wan Kenobi Adobe Community Professional

                                                I tested it With CS4 and CC.

                                                • 21. Re: GREP question
                                                  pixxxel schubser Level 5

                                                  The syntax is wrong.

                                                   

                                                  You can use this instead (this is the same, but in my opinion the correct way):

                                                  (\(?\<[\l\u])\s

                                                  and replace with

                                                  $1~S

                                                  At first should be the

                                                  open parenthesis (perhaps) and than

                                                  the Beginning of the word …

                                                   

                                                  The mistake of Radeks Grep is - if is nothing in $1 than you can't replace any $2 and so on. It seems to be the same problem like finding different things (perhaps) in a positiv lookbehind. That's not possible in InDesigns Regex.

                                                   

                                                  - - - - -

                                                   

                                                  As an example you can test this (wrong) grep too - it's the same with an beginning space (perhaps):

                                                  (\s?)(\(?)(\<[\l\u])\s

                                                  replace with

                                                  $1$2$3~S

                                                   

                                                  Only (and that's a little bit buggy) if $1 and $2 and $3 not empty, you can replace $1$2$3 correctly. Or you use the Button: [change all]

                                                   

                                                  my 50 cent

                                                  • 22. Re: GREP question
                                                    Obi-wan Kenobi Adobe Community Professional

                                                    So … If you can do it, explain me why …

                                                     

                                                    … the regex works if you change all, in one time ;

                                                     

                                                    or

                                                     

                                                    … the regex works if you replace by $2~S and launch the regex step by step (works too if you change all in one time)?

                                                     

                                                    Very annoying!!!

                                                    • 23. Re: GREP question
                                                      Radek Bartunek Level 1

                                                      Fine, I am not ashamed to admit I probably have constructed wrong GREP.

                                                       

                                                      But it has WORKED for months! Really, I used it every day and it did what I wanted... If it did not work at all, I would use other GREP Find expression from the beginning.

                                                       

                                                      (Note: It seems that GREP "find: \<([\l\u])\s - replace with: $1~S" works correctly.)

                                                       

                                                      And no, I did not update InDesign recently (unless any "hidden" update for CS6 was released...)

                                                      • 24. Re: GREP question
                                                        Obi-wan Kenobi Adobe Community Professional

                                                        Radek,

                                                         

                                                        You can use yours with $2~S

                                                         

                                                        You can use a grep style too!

                                                         

                                                        But, finally, better is to use a right grep code! 


                                                        • 25. Re: GREP question
                                                          wideEyedPupil Level 1

                                                           

                                                          Your GREP Find expression is syntactically correct.

                                                           

                                                          (      Begin Group #1
                                                               \<      Beginning of a word
                                                               \(?      Literal opening parenthesis; may occur once, or not at all
                                                          )      End Group #1
                                                          (      Begin Group #2
                                                               [      Inclusion: any character in this group
                                                                    \l      Any lowercase character (a..z)
                                                                    \u      Any uppercase character (A..Z)
                                                               ]      End Inclusion Group
                                                          )      End Group #2
                                                          (      Begin Group #3
                                                               \s      Any white space
                                                          )      End Group #3
                                                          
                                                          
                                                           (1 \< \( ? 1) (2 [ \l \u ] 2) (3 \s 3)

                                                          Is that GREP line by line print out something on the web that can spit out arbitary GREP notation (deconstructed) into is most basic elements or did you type it up by hand?

                                                          • 26. Re: GREP question
                                                            wideEyedPupil Level 1

                                                            Peter Spier wrote:

                                                             

                                                            It occurs to me that this might work better as a GREP style in your paragraph styles than using Find/Change since it would be automatic. You can do that by creating a character style whose only attribute is No Break and apply that using the query.

                                                             

                                                            How do you create a character style with "no break"? I'm not ever sure what this is. Is it like keeping lines together in Paragraph styles?

                                                            • 27. Re: GREP question
                                                              Larry G. Schneider Adobe Community Professional & MVP

                                                              Just Google whattheGREP

                                                              • 28. Re: GREP question
                                                                Peter Spier Most Valuable Participant (Moderator)

                                                                No Break is an atribute that can be applied to selected text that  prevents, as you would expect, a line from breaking in the selected  text. You create sush a style by checking the No Break box under Basic  Character Formats and leaving everyting else alone:

                                                                 

                                                                NoBreak-CharStyle.png

                                                                • 29. Re: GREP question
                                                                  wideEyedPupil Level 1

                                                                  Thanks for the prompt replies on both those questions Peter. Funny I just went and find/replaced all the Fig. n.n and Table n.n references to have non-breaking spaces but a couple of grep styles makes more sense. Loading up with GREP styles doesn't have any performance impact does it, I would hope InDesign wasn't iterating GREP rules every time I enter a character of text into a text field in a long chapter. But maybe it's just optomised very well?

                                                                  • 30. Re: GREP question
                                                                    Peter Spier Most Valuable Participant (Moderator)

                                                                    wideEyedPupil wrote:

                                                                    Loading up with GREP styles doesn't have any performance impact does it, I would hope InDesign wasn't iterating GREP rules every time I enter a character of text into a text field in a long chapter.

                                                                    Actually, that's exactly what happens, so you want to keep GREP styles to just those that make sense. The faster your computer, the less you will notice it, and you probably won't notice it at all until you get up around 6 or so.

                                                                    • 31. Re: GREP question
                                                                      wideEyedPupil Level 1

                                                                      Got it, thanks.