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.
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.
@piraisudan
Does this regex answer your question: {(?<yourfield>.+)}
@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>[^{}]+)\}?\}"
?