8 Replies Latest reply on Mar 18, 2013 11:17 AM by maxhodges0

    need help with a GREP statement

    maxhodges0 Level 1

      I'm trying to select just the x

      舌ぽう (舌鋒x) ぜっぽう (sharp) tongue

      じょう舌 (饒x舌) じょうぜつ garrulity, loquacity

      Its always in parentheses. So I want to LookBehind for a left parenthesis then zero or more characters, and LookAhead for zero or more character followed by a parenthesis.

      I thought this would work, but it doesn't: (?<=\(.?)x(?=.?\))

      This one will select all the text between the parentheses, but I only want the x: (?<=\().?x.?(?=\))

      I also tried this (not sure if you can have two lookbehinds...but it didn't work:

      (?<=\()(?<=.?)x(?=.?)(?=\))

      I'm out of ideas.

        • 1. Re: need help with a GREP statement
          Vamitul Level 4

          that's tricky. lookbehind does not accept variable length.

          the 'easy' way to do it is to do multiple Greps, for each lenght:

          (?<=\(.)x(?=.\))

          (?<=\(.{2}?)x(?=.\))

          (?<=\(.{3})x(?=.\))

           

          etc.

          1 person found this helpful
          • 2. Re: need help with a GREP statement
            [Jongware] Most Valuable Participant

            If the 'x' is always between parentheses, you don't have to check for the opening one -- at least, not 'before'

             

            Try this:

             

            x(?=[^(]*\))

            1 person found this helpful
            • 3. Re: need help with a GREP statement
              maxhodges0 Level 1

              Thanks for the tips. I found an easier way. There is always a space between the Japanese text and the English defintinion so I just get any x before the EN SPACE.

               

              btw do you know if there is a way to get the WIDTH of a selection? like in points or mm?

              • 4. Re: need help with a GREP statement
                [Jongware] Most Valuable Participant

                maxhodges0 wrote:

                 

                btw do you know if there is a way to get the WIDTH of a selection? like in points or mm?

                 

                Sure. (You *are* using a script, aren't you?) Width is can be calculated using the horizontalOffset property of an InsertionPoint (which is slightly different from a 'character', because an IP also can designate the position *after* a character).

                "In points or mm" is Not Applicable. For the vast majority of functions, all measurements are in your current units. So if your current unit is millimeters and you want the distance in points, you have to use UnitValue (a function which I tend to avoid at all cost), or simply do the calculation

                 

                pts = 72 * mm / 25.4

                 

                With InsertionPoints, subtracting the first x offset from the last one, this code will show the width of a selected text:

                 

                alert (app.selection[0].insertionPoints[-1].horizontalOffset - app.selection[0].insertionPoints[0].horizontalOffset);

                1 person found this helpful
                • 5. Re: need help with a GREP statement
                  Laubender Adobe Community Professional & MVP

                  @Jongware – one should be aware that the distance is measured not related to the text's baseline but related to page or spread coordinates.

                   

                  So you will get "not expected" results, if the text frame is rotated (of course that depends on your expectation ;-) ). Even a 0 as distance is possible, if the text frame is rotated by eg. 90°. Or minus values, if its rotated further.

                   

                  In RTL scenarios minus values are to be expected as standard.

                   

                  And this also implies that you cannot measure distances according to the text's baseline, if you are using text on a path, where the path is curved…

                   

                  Uwe

                   

                  Message was edited by: Laubender Old: 180°, New: 90°

                  • 7. Re: need help with a GREP statement
                    [Jongware] Most Valuable Participant

                    > another GREP puzzle!

                     

                    Is this one solved then?

                    • 8. Re: need help with a GREP statement
                      maxhodges0 Level 1

                      I found another way...turns out some "x" I needed to convert were not inside the parentheses, so I found another way to do it (looking ahead for an EN SPACE used to separate the Japanese from English text "x(?=~>)"