Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Don't match full string regex

MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
How do i not match a full string in regex (I want to extract numbers out of it)
mb - draftsman - also FS author: View FeatureScripts
IR for AS/NZS 1100

Best Answers

Answers

  • mthiesmeyermthiesmeyer Onshape Employees Posts: 115
    Hi @mbartlett21

    Perhaps add an example string that you would like to match and some examples that should not match? Are you saying you would like a regex that matches any string that contains at least one number? Or contains all numbers? Or something else?
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    @mthiesmeyer
    I would like a function to evaluate a string (like javascript eval()).
    Example string: "x^2 + y^0.5".

    I was wanting to use something like this to get the numbers in the string
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    @ilya_baran
    How does the Expression type work?
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    It's all defined in that feature studio.  Basically, the idea is that an Expression is just a lambda function, say of one variable, t.  The operators are overloaded for Expression types so that when you, for example, add two Expressions, the result is a function that evaluates the two functions and returns their sum.  Constants are just turned into functions that return that constant, and t_ is the identity function.  So when you write t_ + 3, you get a function that returns 3 plus its argument.  More complicated expressions also just turn into functions that evaluate them.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    @ilya_baran
    Is it faster evaluating through a few functions to get the value, or would functions that returned reverse polish notation be faster?
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    Neither will be terribly fast.  I'm not sure which is faster -- you'd have to measure.  I have a vague plan of using operator/function overloading to construct an expression tree in FS and have builtin functions compile it using LLVM, but that's far out.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    What is LLVM?
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    Ilya, would there be any way to have an input like

    annotation { "Name" : "Input", "Variables" : ["var1","var1"]}
    definition.input is Expression;

    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,034 EDU
    Here is my evalExpression script now (it first splits the tokens, turns that to Reverse Polish Notation, then evaluates it. It also allows contxts and lists of variables to be input, like x, y, etc.):
    https://cad.onshape.com/documents/429fd7dda5f0fdb93833a34a
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
Sign In or Register to comment.