Page 1 of 1
Extracting numbers from a string
Posted: Fri May 27, 2016 12:08 pm
by kevin007
Hi ALL
I have an variable that contain following string .
[xshift={\hzwidth+10} ,yshift={-\vtheight+15}, rotate=30]
I want only numbers from above string and save these three numbers to three different variable

Re: Extracting numbers from a string
Posted: Fri May 27, 2016 12:15 pm
by Thierry
kevin007 wrote:
[xshift={\hzwidth+10} ,yshift={-\vtheight+15}, rotate=30]
I want only numbers from above string and save these three numbers to three different variable
Hi Kevin,
If you don't have any allergia with regex, here is one solution:
Code: Select all
if matchText( S, "\+(\d+)}.+\+(\d+)}.+=(\d+)]", n1, n2, n3) then
put "Find: " & n1 && n2 && n3
else
put "Sorry, no match!"
end if
Just typed it out of my head, so beware of possible typos.
Best,
Thierry
Re: Extracting numbers from a string
Posted: Fri May 27, 2016 12:31 pm
by kevin007
@Thierry
superb coding

Re: Extracting numbers from a string
Posted: Fri May 27, 2016 3:57 pm
by dunbarx
Thierry can do more with one line of regex than I can in a handful of lines of "ordinary" code.
But are you OK with that, or do you want to talk about those handfuls?
Craig Newman
Re: Extracting numbers from a string
Posted: Fri May 27, 2016 5:16 pm
by Thierry
dunbarx wrote:Thierry can do more with one line of regex than I can in a handful of lines of "ordinary" code.
Hi Craig,
Mmm, I have nothing to do with this fact; that's the power of regex: concise and powerful for
pattern matching.
But are you OK with that, or do you want to talk about those handfuls?
Well, I think it will be nice to have some 'Livecodish' solutions, and let the readers learn,
compare and experiment out of them.
My 2 cents,
@Kevin: Re-reading my post, I've noticed there are some room for speeding up the regex.
If you feel it's too slow, just let me know.
But now, I have to unplug all my computers as a big storm is coming.
Thierry
Re: Extracting numbers from a string
Posted: Fri May 27, 2016 5:37 pm
by Klaus
Bonsoir Thierry,
Thierry wrote:dunbarx wrote:Thierry can do more with one line of regex than I can in a handful of lines of "ordinary" code.
Hi Craig,
Mmm, I have nothing to do with this fact; that's the power of regex: concise and powerful for
pattern matching.
JAMAIS, mon ami!
I still consider this WITCHCRAFT!
Have a nice weekend!
Klaus
Re: Extracting numbers from a string
Posted: Fri May 27, 2016 5:48 pm
by Thierry
Klaus wrote:Bonsoir Thierry,
JAMAIS, mon ami!
I still consider this WITCHCRAFT!
So be careful when talking to me that I'm not going to cast a spell on you
Schönes Wochenende
Regards,
Thierry
Re: Extracting numbers from a string
Posted: Fri May 27, 2016 5:52 pm
by Klaus
Thierry wrote:Klaus wrote:Bonsoir Thierry,
JAMAIS, mon ami!
I still consider this WITCHCRAFT!
So be careful when talking to me that I'm not going to cast a spell on you
Schönes Wochenende
Regards,
Thierry
