10 Replies Latest reply on Jun 21, 2017 4:47 AM by Obi-wan Kenobi

    Fractions in GREP

    Dative Level 1

      Is there a 'wildcard' or the equivalent through which I can select all fractions in GREP?

        • 1. Re: Fractions in GREP
          vinny38 Level 5


          You should be more specific about the patterns of what you call "fractions".

          Something like this: (a certain number of digits)+(a slash)+(a certain number of digits) maybe? Like 450/50

          Or do you have separators? 27/1.5 or 27/1,5? Or even 1(space)500/2 or 5,500.50/3

          Or maybe something completely different, possibly built with some math font?


          Please provide more details, being as specific as possible (screenshots can also help)


          • 2. Re: Fractions in GREP
            dhafirp16891848 Level 1

            Try this code: (\d+\.\d+)|[/\d]|\p{no}

            • 3. Re: Fractions in GREP
              Dative Level 1

              Okay so I need to be more specific, what I'm trying to do is find WxH measurements and flip them to HxW.


              This is my code so far.


              and change to


              While this finds inches I need to be able to find centimetres as well. This is easy enough to do in two steps but I was hoping there was a more elegant solution with one. The structure of the measurements is always as follows


              30 × 29 ⅞ in. (78 × 76 cm)


              With the numbers varying obviously.


              \d doesn't find fractions in the typeface I'm using because they're an individual glyph rather than composite parts.


              I think I need a GREP expression like this (\d+~<(possible fraction))( ~<×~< )(\d~<(possible fraction))(?=~<in\.|~<cm\))


              I seem to remember theres a way using a question mark you can say 'this may appear or it may not' so ideally I'd like it to be ?wildcard for fractions.

              • 4. Re: Fractions in GREP
                Dative Level 1

                I should also note there's probably a way to do it without having to denote the fractions, I would just need the 'any character' expression to end at in. otherwise this happens.


                Screen Shot 2017-06-20 at 15.57.13.png

                • 5. Re: Fractions in GREP
                  dhafirp16891848 Level 1

                  Try this: (\p{n*}+)(\s×\s)(\p{n*}+\s\p{n*}?)(?=\(?\s?(in|cm))

                  • 6. Re: Fractions in GREP
                    vinny38 Level 5


                    To find your fractions, you can use set of Unicode ranges.

                    Given this site: Searching in Unicode character names for fraction, there are two sets of fractions that could be used to reach fractions (should be tested):

                    U00BC to U00BE and U2153 to U215E

                    Grep query for Unicode range is like this : [\x{Unicode}-\x{Unicode}]

                    So in your case, [\x{00BC}-\x{00BE}\x{2153}-\x{215E}] should catch your fractions.

                    Please notice I've also used the Unicode search pattern to get the multiplication sign.








                    Now, this is very verbose and not very elegant

                    Maybe Grep enthusiasts (Peter Kahrel, Obi-wan Kenobi, and many more) could come up with a better query.


                    Hope that helps anyway


                    1 person found this helpful
                    • 7. Re: Fractions in GREP
                      Peter Kahrel Adobe Community Professional & MVP

                      Nice one, vinny38. But you can match fractions with the Unicode property \p{Other_number} (or \p{No} in its abbreviated form). But unfortunately you can't use Unicode properties in character classes, so that [\d\.\p{No}] doesn't work. So you'd get something like this:


                      ((?:\d[\d.]+)(?:\s\p{No})?)   // A digit followed more digits or dots, maybe followed by a space and an 'other' number.


                      ((?:\d[\d.]+)(?:\s\p{No})?)  // Another number



                      It's not entirely clear which one bends the mind more . . .



                      2 people found this helpful
                      • 8. Re: Fractions in GREP
                        vinny38 Level 5

                        Thanks a lot for your answer Peter,

                        I've seen this \p{No} property in dhafirp16891848's answer but couldn't figure out what it was.

                        Much more clear now, although I have no idea on how we could figure that fractions are "other numbers". But that's a specialist call.

                        Also not forgetting about possible dots is definitely a good idea ^^

                        Nice stuff...

                        1 person found this helpful
                        • 9. Re: Fractions in GREP
                          Peter Kahrel Adobe Community Professional & MVP

                          The Unicode properties aren't documented in InDesign itself. The Find/Change dialog's flyout you can use to insert codes is pathetic, many codes are missing.


                          This script corrects that and adds a few useful things: http://www.kahrel.plus.com/indesign/grep_classes.html



                          3 people found this helpful
                          • 10. Re: Fractions in GREP
                            Obi-wan Kenobi Level 5





                            Find:  (\d+.+?)(~<×~<)((?1))(?=~S(in\.|cm))

                            Replace by:  $3$2$1



                            2 people found this helpful