Splunk Search

How do you write a regular expression to extract a field which has characters, numbers and also special characters?

Deepz2612
Explorer

How do you write a regular expression to extract a field which has characters, numbers and also special characters? There are sometimes spaces in between.

I tried this. rex "(?\w+[A-Z0-9][^-])" --- to include characters and hyphen,
but it doesnt work

Thanks in advance!!

Tags (2)
0 Karma
1 Solution

vnravikumar
Champion

Hi @Deepz2612

Try this, I included space and hyphen

([A-Za-z0-9*,\s-])

View solution in original post

0 Karma

kushagra9120
Explorer

this works for me :-

[\w\D]*

It would be better if you give the input data as well

0 Karma

vinod94
Contributor

hi @Deepz2612 ,

you can try this,

| rex "(?P<field_name>[a-zA-Z0-9\s].*)"
0 Karma

MoniM
Communicator

Hi @Deepz2612 ,

I tried this:-
([\w\D]+) for extracting "tirx-Ten @140gmail.com"

Thanks

0 Karma

FrankVl
Ultra Champion

\w includes digits, \D is non-digits. So combining those two means you match basically anything.

0 Karma

FrankVl
Ultra Champion

It would help if you would post some sample data and requirements on what you need to extract.

Regarding the regex you have: put it in on regex101.com and see the explanation of what it does, maybe that helps you spot the flaw.

Also: when posting code like that, please put it in between backticks: ` or use the 101010 button in the message editor toolbar to post it as a code snippet, so special characters don't disappear.

vnravikumar
Champion

Hi @Deepz2612

Try this, I included space and hyphen

([A-Za-z0-9*,\s-])

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...