Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6230805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:49:08+00:00 2026-05-24T09:49:08+00:00

Need a regular expression to match { and } . Here is my requirement.

  • 0

Need a regular expression to match { and }.

Here is my requirement.

If the input is like

avsg{sdhsd{jh{ashdhas}hdasjhd}

…the output should be

avsgsdhsdjh{ashdhas}hdasjhd

I have to trim all the occurrences of { and } except if there is a matching } for a {.

EDIT — some further examples:

Nested brackets are not allowed. We allow ‘{‘ and ‘}’ that too only once and we remove all the brackets. Giving some more examples.

1). IN:afhad{adfh}jsdfhd OUT: afhad{adfh}jsdfhd

2). IN:afhad{a{dfh}jsdfhd OUT: afhada{dfh}jsdfhd

3). IN:afh{ad{adfh}jsdf}hd OUT:afhad{adfh}jsdfhd

4). IN:afhad{adfhjsdfhd OUT:afhadadfhjsdfhd

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:49:09+00:00Added an answer on May 24, 2026 at 9:49 am
    s = Regex.Replace(s, @"([^{}]*(?:\{[^{}]*\}[^{}]*)*)(?:[{}]|$)", "$1");
    

    [^{}]* matches zero or more of any characters except { or }.

    \{[^{}]*\} matches an opening brace followed by a closing brace, with any number of any characters except braces between them.

    All together, ([^{}]*(?:\{[^{}]*\}[^{}]*)*) matches zero or more non-braces or matched pairs of braces and captures them in group #1, and then (?:[{}]|$) matches the next unpaired brace or the end of the input. Replacing the match with $1 (the contents of group #1) effectively deletes the unpaired brace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to match using regular expression in php addresses like: 144 street, city,
I need a Perl regular expression to match a string. I'm assuming only double-quoted
I need a regular expression able to match everything but a string starting with
I need a regular expression that will match the first letter of a song
I need to match and remove all tags using a regular expression in Perl.
I need to write a regular expression that finds javascript files that match <anypath><slash>js<slash><anything>.js
i need a regular expression to match only the word's that match the following
I am assuming I need a regular expression here? I have a zip code
I need a regular expression that will match the file name of a ResourceBundle
I need a regular expression that will match text enclosed in parentheses. The parentheses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.