Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP for numeric digits and their corresponding units of measurement

Return to Member Forum

  • Author
    Posts
    • #60236
      Kelly Vaughn
      Participant

      I am trying to figure out how to write a grep code that will automatically look for:

      15 mL or 15 mm or 15 min or 15 kg or 15 ng or 15 kg or 15 ng/kg or 15 mL/min or 15 μg/kg…

      There are a lot of different possibilities I need to account for. Sometimes the units of measurements will have two units (voume/time) and the slash needs to be part of the expression. I was able to get it to work by making a bunch of different grep styles, but I'm brand new to grep and am having a hard time wrapping my head around subepxressions. Here is my initial attempt (which obviously failed).

      d+(μg/kg)|μg|kg|μL|ng/kg|ng|kg|mm|mL

      Please help. Thanks.

      Kelly Vaughn

    • #60240

      Well, one one level the combinations are endless — Newton's Gravitational Constant, g, for example, is defined in cubed meters per grams per seconds squared, or m³/gs² — but given a few constraints, you could use the metric system of optional prefix and required unit to your advantage:

      d+s?(([pnμmcdkMG]?[gmL])(/([pnμmcdkMG]?[gmL]))*)

      This is, from left to right,

      any number of digits (but no fractions allowed)

      no or only one kind of white space (this was missing in your own attempt)

      nothing, or one of the pico, nano, micro, milli, centi, deci, kilo, mega, or giga prefixes

      g for grams or L for Liter or m for meter

      zero or umpteen of the following group:

      { a slash

      followed by (again) a prefix and a unit. }

      This misses the minute (min) in your example, but then again that's not an official SI unit :P

Viewing 1 reply thread
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads