Options

Best way to convert Nominal values by using expressions

DoomyDoomy Member Posts: 2 Contributor I
edited July 2021 in Help
I’ve set of data with INCH measurement unit , the values are so missy and I’m trying to figure out a way to unified them and convert them to a way I can work with them 
Example of the values : 
  1. 1/8 , 1/16 , 19/17 , 13/3 , 1.1/8
  2. 0.139 , 0.07 , 3.37  , .250 , 0.14
  3. 3-1/8 , 1-1/26 , 1-18/23 , 10-1/2
  4. 20 , 3 , 10 
  5. 0.30-0.40  
  6. 0.094+/-0.004 
  7. 1.046 ( 1-1/16)
  8. Some of them have text and numbers 
I’ve read about regular expression but how I can defined the regular expression and use it in Rapid Minor to divide these complex values. 
If there’s any other way to solve this issue I would appreciate any suggestions to solve that.

Best Answer

  • Options
    kaymankayman Member Posts: 662 Unicorn
    Solution Accepted
    Don't know too much on how inches work, but since your values seem seperated by comma's you could use that to split the strings into single values. If you want to keep inches you can than normalize these by replacing '-' to '.' or the other way around.

    If you need to convert to mm you can than generate a regex that converts the full inches and the 'sub inches'. Not sure how it's really called...

    As an example, if you have 3-1/16 and have a regex like this : 

    ^(d+)?[.-]?(?:(\d+)/(\d+))?

    You read this like 'you start with optional full digits, followed by an optional hyphen or dot, and then you have the optional divider. 

    Your first group would be 3, the second 1, and the third one 16, so you could create something like

    ($1 * 25.4) + ((25.4 / $2)/$3) to convert to mm. I have no clue if my conversion is correct by the way, but you get the idea.

    Now, this works if you have a full match, in case of partials like 2/16 (so no full digits) or 20 (so no divider) it means your replacement needs to be adjusted 
Sign In or Register to comment.