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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...