
1. Re: Fractions in GREP
vinny38 Jun 20, 2017 7:40 AM (in response to Dative)Hi
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)
Vinny

2. Re: Fractions in GREP
dhafirp16891848 Jun 20, 2017 7:40 AM (in response to Dative)Try this code: (\d+\.\d+)[/\d]\p{no}

3. Re: Fractions in GREP
Dative Jun 20, 2017 7:51 AM (in response to vinny38)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.
(.+)(~<×~<)(.+)(?=~<in\.)
and change to
$3$2$1While 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.


5. Re: Fractions in GREP
dhafirp16891848 Jun 20, 2017 8:29 AM (in response to Dative)Try this: (\p{n*}+)(\s×\s)(\p{n*}+\s\p{n*}?)(?=\(?\s?(incm))

6. Re: Fractions in GREP
vinny38 Jun 21, 2017 12:39 AM (in response to Dative)1 person found this helpfulHi
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.
Search:
([\d~<\x{00BC}\x{00BE}\x{2153}\x{215E}]+)(~<\x{00D7}~<)([\d~<\x{00BC}\x{00BE}\x{2153}\x{215E}]+)(?=~<in\.~<cm\))
Replace:
$3$2$1
Now, this is very verbose and not very elegant
Maybe Grep enthusiasts (Peter Kahrel, Obiwan Kenobi, and many more) could come up with a better query.
Hope that helps anyway
Vinny

7. Re: Fractions in GREP
Peter Kahrel Jun 21, 2017 1:39 AM (in response to vinny38)2 people found this helpfulNice 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.
\s×\s
((?:\d[\d.]+)(?:\s\p{No})?) // Another number
(?=\s(in\.cm))
It's not entirely clear which one bends the mind more . . .
Peter

8. Re: Fractions in GREP
vinny38 Jun 21, 2017 1:56 AM (in response to Peter Kahrel)1 person found this helpfulThanks 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...

9. Re: Fractions in GREP
Peter Kahrel Jun 21, 2017 2:07 AM (in response to vinny38)3 people found this helpfulThe 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
P.

10. Re: Fractions in GREP
Obiwan Kenobi Jun 21, 2017 4:47 AM (in response to Dative)2 people found this helpfulHi,
Try:
Find: (\d+.+?)(~<×~<)((?1))(?=~S(in\.cm))
Replace by: $3$2$1
(^/)