Dashboards & Visualizations

Help me with Regex

SabariRajanT
Path Finder

Hi Team, Am trying to write a regex function to remove the logs post / slash everything. The sample logs are here:
Sample logs:
1) ws.chatgpt.com/re/user/sdsdssdsd?verify=1757077758-CSPsqhWt%sdserere%2BJ7IesevE6CTs%3D
2)win-extension.femrerere.grammarly.io/batch/import

The / logs are not same. they are dynamic. 

Expected post Regex: ws.chatgpt.com
win-extension.femetrics.grammarly.io

Can someone please help me to write a regex for the same.

Labels (1)
Tags (1)
0 Karma

PrewinThomas
Motivator

@SabariRajanT 

If you don't want to create new field, use simple rex mode=sed

| makeresults
| eval url="ws.chatgpt.com/re/user/sdsdssdsd?verify=1757077758"
| rex field=url mode=sed "s:/.*::"
| table url


If you want to create new fields like domain/url for creating any visualization/reporting use below,

 

| makeresults count=1
| eval raw_log="ws.chatgpt.com/re/user/sdsdssdsd?verify=1757077758-CSPsqhWt%sdserere%2BJ7IesevE6CTs%3D,win-extension.femrerere.grammarly.io/batch/import"
| makemv delim="," raw_log
| mvexpand raw_log
| rex field=raw_log "^(?<domain>[^/]+)"
| table raw_log domain

Regards,
Prewin
If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!

0 Karma

glass
Splunk Employee
Splunk Employee

Hi,
you can try this: 

| makeresults format=csv data="url
ws.chatgpt.com/re/user/sdsdssdsd?verify=1757077758-CSPsqhWt%sdserere%2BJ7IesevE6CTs%3D
win-extension.femrerere.grammarly.io/batch/import
" 
| rex field=url "^(?<url_short>[^\/]+)" 
| table url, url_short

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this SPL command 

| rex mode=sed "s:([^\/]+):\1:"

To make the change at index time, put this in props.conf:

[mysourcetype]
SEDCMD-postSlash = s:([^\/]+):\1:
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...