Sorry if I've missed this in the documentation, but I don't see it, and it 
is starting to bother me.

In Powershell. Python, and Splunk I'm able to perform automatic field 
extraction on strings and access the values of fields by name.  Is there a 
way to do this in Racket?  Of course, pairing matches with field names by 
index is an option, but not as convenient in some situations.

Take string "2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 
something 
broke" as a trivial example.

Powershell:
"2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 something 
broke" -match 
"^(?<Date>[\d\-T:]+)\s(?<Username>\w+)\s(?<Hostname>[\w\-\d]+)\s(?<IP>[\d\.]+)\s(?<Message>.+)$"
 
| Out-Null

$matches.date
$matches.username
$matches.hostname
$matches.IP
$matches.message

Python:
m = re.match(
"^(?P<Date>[\d\-T:]+)\s(?P<Username>\w+)\s(?P<Hostname>[\w\-\d]+)\s(?P<IP>[\d\.]+)\s(?P<Message>.+)$"
, "2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 something 
broke")

m['Date']
m['Username']
m['Hostname']
m['IP']
m['Message']

Both output:

2018-02-02T11:26:34
someuser
some-computername01
233.194.20.110
something broke

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to