Retrieving Numbers - 26/11/03 01:00 AM
In 192d29h1m, how could I get the number before the d, the h and the m? Any of the numbers can change, or certain sections (e.g. '192d' or '29h') could be missing.
moo { [color:red]; Call regular expression. All results will be [i]x[/i] amount of numbers ending with a single letter.[/color] !.echo -q $regex(parsetime, $$1, /(\d+[a-z])/gi) var %i = 1 [color:red]; Loop through results of regular expression call[/color] while $regml(parsetime, %i) { [color:red]; Assign rightmost character (the letter) to %char. Assign everything else to %num.[/color] var %char = $right($ifmatch,1), %num = $left($ifmatch,-1) [color:red]; If %char is d set %num variable %days[/color] if (%char == d) var %days = %num [color:red]; Hours checking/assignment...[/color] elseif (%char == h) var %hours = %num [color:red]; Mins checking/assignment...[/color] elseif (%char == m) var %mins = %num inc %i } echo -a %days $+ days %hours $+ hours %mins $+ mins }
mootoo { var %a = $$1 !.echo -q $regsub(%a,/(\d+[a-z])/gi,\1 $chr(32),%a) echo -a $duration($duration(%a)) }