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
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...