Hi
I hope that it is OK to post this here, please say if not…
I’m pretty new to ruby and regular expressions. I would like to use a
regular expression to match only numbers contained within square
brackets. e.g. a sentence may be…
[1] to [2], corresponding to [3] to [4] output using IRP 829 Version
2XX, [5] to [6] output using IRP 452 Version 3XX
The numbers are refences to specifications in another table. At the
moment, I use /[\d*]/ This extracts the numbers including brackets,
but now can I just extract the numbers by altering the expression? The
full ruby code I use for this is as follows if this is any use, probably
also there is a better way than splitting on a space…
Any help would be great and really appreciated.
Many thanks
Darren
<%if (opt==“display”)%>
<%cycles = 1
n = 0
@text_line = “”
for part in @translation.text_line.split(’ ')
if ((/[\d*]/).match(part))
if (@fields[n])
@[email protected]_unit(@fields[n].unit_id).name
@[email protected]_prefix(@fields[n].prefix_id).name
if (@translation.text_line.split(' ').size==cycles)
@text_line = "#{@text_line}"+"#{@fields[n].result}"+"
“+”#{@prefix_new}"+"#{@unit}"
else
@text_line = “#{@text_line}”+"#{@fields[n].result}"+"
“+”#{@prefix_new}"+"#{@unit}"+" "
end
end
n += 1
else
if (@translation.text_line.split(’ ').size==cycles)
@text_line = @text_line+"#{part}"
else
@text_line = @text_line+"#{part}"+" "
end
end
cycles += 1
end
end%>