I have the following piece of code:
nonce = data.scan(/nonce="(.*)"/)
data is a string ,the matched piece of string is assigend to nonce variable which automatically becomes an Array.
Now, if i
puts nonce[0]
I will get my value printed correctly:
51d8852d
but if use:
puts "final string #{md1}:#{nonce[0]}:#{md2}"
the output will be:
df49f55acfd9d21837fd840644f251b4:["51d8852d"]:3b7718806908d2a4456086be7daba94ccd36ea19fd2bfa80ae41fa8be23433b7
but there shouldn’t be any brackets or duoble quotes, i should get only the array’s value.
It should be something like this:
df49f55acfd9d21837fd840644f251b4:51d8852d:3b7718806908d2a4456086be7daba94ccd36ea19fd2bfa80ae41fa8be23433b7
Could you please suggest me how to solve this issue?
Thanks
Dawid
When you use scan with a capture group, the result is an array of arrays, so you want to use
nonce[0][0]. You got confused because your first example feedsnonce[0], which is an array, toputs, which handles arrays by printing out each element. If you doputs nonce[0].class, you’ll see…