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.
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

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

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...