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 Posts: 1,693 EDU
How do i not match a full string in regex (I want to extract numbers out of it)
MB - I make FeatureScripts:View FeatureScripts

Best Answers

Answers

  • mthiesmeyermthiesmeyer Onshape Employees Posts: 88
    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 Posts: 1,693 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 - I make FeatureScripts:View FeatureScripts
  • MBartlett21MBartlett21 Member Posts: 1,693 EDU
    @ilya_baran
    How does the Expression type work?
    MB - I make FeatureScripts:View FeatureScripts
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 952
    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 \ Director, Architecture and FeatureScript \ Onshape Inc
  • MBartlett21MBartlett21 Member Posts: 1,693 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 - I make FeatureScripts:View FeatureScripts
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 952
    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 \ Director, Architecture and FeatureScript \ Onshape Inc
  • MBartlett21MBartlett21 Member Posts: 1,693 EDU
    What is LLVM?
    MB - I make FeatureScripts:View FeatureScripts
  • owen_sparksowen_sparks Member, Developers Posts: 2,495 PRO
    Production Engineer
    HWM-Water Ltd
  • MBartlett21MBartlett21 Member Posts: 1,693 EDU
    Ilya, would there be any way to have an input like

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

    MB - I make FeatureScripts:View FeatureScripts
  • MBartlett21MBartlett21 Member Posts: 1,693 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 - I make FeatureScripts:View FeatureScripts
Sign In or Register to comment.