Forum: Ruby Some basic search help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F4bacb8bf99c776f4d28d9da11e77d1d?d=identicon&s=25 Dw Dwdw (dwdwdw)
on 2016-11-15 23:29
I’m looking to filter the logs messages going into pick out the
location, store, operator and nonce.



Nov 15 20:16:25 PROD SERVER:  [ERROR]
c.q.s.w.c.mycompanyControllerAdvice:
logTraceId=f498cef6516543e1a70dc9bad5f7358a, order=36276,
nonce=CC41B399-6664-4E88-8A17-1DD30327175C, location=20655,
restaurant=294, operator=42
com.mycompany.server.exceptions.pos.mcp.McpException


Can anyone help? Happy to focus on location first.

^ I need something in here I think (location=)\d
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-11-16 14:49
Given a string such as the one you have posted, you can get the location
by applying the regexp

  / location=(\d+)/

but in any case, there are several possible solutions. For example, are
alsways all these fields supplied, in exactly the same sequence? Would
it preferable (more flexible) to have all NAME=VALUE pairs extracted
from the string?
F4bacb8bf99c776f4d28d9da11e77d1d?d=identicon&s=25 Dw Dwdw (dwdwdw)
on 2016-11-18 16:20
Hi Ronald,

Thanks for this. I need each NAME=VALUE extracted but not all together
in the one expression. I need each separately.

Taking your example above, how would I only select the numbers after the
'location='?
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-11-21 11:57
String#scan is your friend.

Assuming that the whole line is stored in variable whole_line, the
expression

    whole_line.scan((\w+)=(\w+))

returns an array of pairs, where the first element of each pair is the
NAME, and the second element is the value.
This topic is locked and can not be replied to.