Forum: Ruby Some basic search help

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 14:52
Ronald Fischer wrote in post #1185251:
> 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?

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='?
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.