Splunk Search

AND condition in Regex

Piraisudan
New Member

I need solution for the following example,

My String : {{My_pa{ss}word}}
In this string I want to select only starting { and } bracket. I tried with this regex ^{|}$ and it selects exactly the first and last bracket what I want. But I have one problem, If my string is {{my_password}} then only it want to select first and last bracket. If my string like this {{my_password, it don't want to select that starting bracket.How to solve this problem?

Give me suggestions...
Thanks.

Tags (1)
0 Karma

DalJeanis
Legend

In order to answer your question, we would have to understand what you mean by "select only" those brackets, and whether it matters which brackets are being selected to get that result. Your example of ^{|}$ should, in fact, only match a line that has either a single open or close brace on it. (^\{|\}$) would match either the open or close brace on a line (but not both).

1) Please produce a table with two columns. In the left column, put the sample data. In the right column, put the data that you want extracted.

2) Using the literal my_password is confusing the issue, since it has nothing to do with what you are asking. Please just use arbitrary letters , unless the specific letters matter for the extraction.

3) The more you tell us about your use case, the better we can help you. If you are attempting to extract only the first and last braces, when there are no braces between them, and then put them together in a single extracted field for some reason, then we need lots of context to help you solve your real business problem.

amiftah
Communicator

@piraisudan
Does this regex answer your question: {(?<yourfield>.+)}

https://regex101.com/r/KMbwZk/2

0 Karma

DalJeanis
Legend

@amiftah - not bad. You probably need to create a synthetic character class [^{}]+ to eliminate curly braces...but that depends on what the OP meant...

perhaps "\{\{?(?<stuff>[^{}]+)\}?\}"?

0 Karma
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...