Copy link to clipboard
Copied
Is there a 'wildcard' or the equivalent through which I can select all fractions in GREP?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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$1
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Try this: (\p{n*}+)(\s×\s)(\p{n*}+\s\p{n*}?)(?=\(?\s?(in|cm))
Copy link to clipboard
Copied
Hi
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 (pkahrel, Obi-wan Kenobi, and many more) could come up with a better query.
Hope that helps anyway
Vinny
Copy link to clipboard
Copied
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.
\s×\s
((?:\d[\d.]+)(?:\s\p{No})?) // Another number
(?=\s(in\.|cm))
It's not entirely clear which one bends the mind more . . .
Peter
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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
P.
Copy link to clipboard
Copied
Hi,
Try:
Find: (\d+.+?)(~<×~<)((?1))(?=~S(in\.|cm))
Replace by: $3$2$1
(^/)
Copy link to clipboard
Copied
Try this code: (\d+\.\d+)|[/\d]|\p{no}