Extracting digits before and after the commaHi,
I'm struggling from extracting digits from a string before and after the comma
how can I get 0.98 and 0.97 from a string?
string = "A_BD_CEEE:0.98,0.975620708";
first_number = Num( Regex( string, "(\d\d?\d?):", "\1" ) );
expected out
first_number = 0.98
second_number = 0.975
thanks</CODE></P><P> </P></LINGO-BODY><LINGO-LABS id="lingo-labs-377493" slang="en-US"><LINGO-LABEL>Scripting</LINGO-LABEL></LINGO-LABS><LINGO-SUB id="lingo-sub-377515" slang="en-US">Re: Extracting digits before and after the comma</LINGO-SUB><LINGO-BODY id="lingo-body-377515" slang="en-US"><P>Here is how I would do it</P>
<PRE><CODE class=" language-jsl">names default to here(1);
string = "A_BD_CEEE:0.98,0.975620708";
first number=num(word(2,string,":,"));
second number = round(num(word(3,string,":,")),3);
Re: Extracting digits before and after the commaIf the numbers cannot be negative this should work:
Names Default To Here(1);
string = "A_BD_CEEE:0.98,0.975620708";
numString = Regex Match(string, "(\d+.\d*),(\d+.\d*)");
first_number = Num(numString[2]);
second_number = Num(numString[3]);
Show(first_number, second_number);
Re: Extracting digits before and after the commaIn addition to the solution of @jthi ,
there is quite a good documentation on regex:
https://www.jmp.com/support/help/en/16.0/jmp/regular-expressions.shtml#
The problem of your initial approach was, that there is no number before :, only after.
And you need to include the . into the string to get the first number. See changes below.
Regex is worth to learn because it is really powerful.
string = "A_BD_CEEE:0.98,0.975620708";
first_number = Num( Regex( string, ":(\d.\d?\d?)", "\1" ) );