Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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
MBartlett21
Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭
How do i not match a full string in regex (I want to extract numbers out of it)
0
Best Answers
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565If you include a capture group in your regexp e.g.
[a-z]^([1-9]+)
, the value of that group will be in the resulting "captures" array.
From the match() documentation:captures {array} : The first element is always the input string s. The following elements are a list of all captured groups
5 -
ilya_baran Onshape Employees, Developers, HDM Posts: 1,212Adding to Kevin's response: you can always add .* on both sides of a regexp to make it match a substring. You should also look at REGEX_NUMBER_CAPTURE -- that can help you extract real numbers (not just integers) from a regexp.
Finally, a much more reliable alternative to parsing strings is the lambda-based expression evaluation that Mahir and I used for the parametric curve and surface features: https://cad.onshape.com/documents/578ff8b3e4b0e65410fcfda3/w/d33395f174e5b38f4abd6097/e/0c17de6a800d4aed83de417fIlya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
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?
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
IR for AS/NZS 1100
[a-z]^([1-9]+)
, the value of that group will be in the resulting "captures" array.From the match() documentation:
Finally, a much more reliable alternative to parsing strings is the lambda-based expression evaluation that Mahir and I used for the parametric curve and surface features: https://cad.onshape.com/documents/578ff8b3e4b0e65410fcfda3/w/d33395f174e5b38f4abd6097/e/0c17de6a800d4aed83de417f
How does the Expression type work?
IR for AS/NZS 1100
Is it faster evaluating through a few functions to get the value, or would functions that returned reverse polish notation be faster?
IR for AS/NZS 1100
IR for AS/NZS 1100
HWM-Water Ltd
IR for AS/NZS 1100
https://cad.onshape.com/documents/429fd7dda5f0fdb93833a34a
IR for AS/NZS 1100