I have a column and I need to extract the numbers from the strings in each row. The numbers could be decimals or not.
I am using this formula: Regex( :PIPE_LENGTH, "[^(\d+\.\d+)]", "", globalreplace )
String: Length = 3.5". Completed by John.
Completed for CEC. Pipe depth- 4.5" (MER)
Why are the extra periods and parentheses coming in? Also, I am confused by the ^ at the beginning. When I remove it I get text only and not the numbers.
This is better. I do have a scenario such as:
John cut 5"
This does not have decimal. Your example is returning blank.
I thought of another case: "Mark cut off .5" of his finger." I am stuck! I can't get my regex to work with this case and the others. Its one set of cases or the other!
Using look ahead...
Names Default to Here( 1 ); PIPE_LENGTH = "Length = 3.5\!". Completed by John."; PIPE_LENGTH = "Completed for CEC. Pipe depth- 4.5\!" (MER)"; PIPE_LENGTH = "John cut 5\!""; PIPE_LENGTH = "Mark cut .5\!" off his finger."; Regex( PIPE_LENGTH, "\D*(?=\.)?(\d*\.?\d*)\D*", "\1" );
I wonder if using JMP Patterns would be easier.
@Craige_Hales , where are you???
Text explorer uses this pattern for numbers
([\-\+]? ?[\.,]?[0-9][\.,0-9]*( ?e ?[\-\+]? ?\d+)?)
reading it from left to right
the commas and periods are interchangeable because of different standards in various countries for how decimals and thousands separators are represented. There are some odd strings that could slip through that are not numbers, so you should write your code to expect the num() function might return a missing value.
There are no labels assigned to this post.