John Smith John Smith - 5 months ago 14
Ruby Question

extracting data through regexps is returning nil

I'm trying to extract a pair of string from a parsed PDF and I have this extract:

Number:731 / 13/06/2016 1823750212 10/06/2016\n\n\n\n Articolo


http://rubular.com/r/GRI6j4Byz3

My goal is to get out the
731
and
1823750212
values.

I tried something like
text[/Number:(.*)Articolo/]
for the first steps but it's returning
nil
while on rubular it somewhat matches.

Any tips?

Answer

Whether the format of the string is fixed (dates and the long number,) this will do the trick:

text.scan /\ANumber:(\d+).*?(\d{5,})/
#⇒ [[ "731", "1823750212" ]]