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!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...