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

  • SEARCH
  • Home
  • 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 8754593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:39:28+00:00 2026-06-13T13:39:28+00:00

I’m looking for a regex in order to transform something like {test}hello world{/test} and

  • 0

I’m looking for a regex in order to transform something like

{test}hello world{/test} and {again}i'm coming back{/again} in hello world i'm coming back. 

I tried {[^}]+} but with this regex, I can’t have only what I have in the test and again tags. Is there a way to complete this regex ?

  • 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-06-13T13:39:29+00:00Added an answer on June 13, 2026 at 1:39 pm

    Doing this properly is generally beyond the capabilities of regular expressions. However, if you can guarantee that those tags will never be nested and your input will never contain curly brackets that do not signify tags, then this regex could do the matching:

    \{([^}]+)}(.*?)\{/\1}
    

    Explanation:

    \{        # a literal {
    (         # capture the tag name
    [^}]+)    # everything until the end of the tag (you already had this)
    }         # a literal }
    (         # capture the tag's value
    .*?)      # any characters, but as few as possible to complete the match
              # note that the ? makes the repetition ungreedy, which is important if
              # you have the same tag twice or more in a string
    \{        # a literal {
    \1        # use the tag's name again (capture no. 1)
    }         # a literal }
    

    So this uses a backreference \1 to make sure that the closing tag contains the same word as the opening tag. Then you will find the tag’s name in capture 1 and the tag’s value/content in capture 2. From here you can do with these whatever you want (for instance, put the values back together).

    Note that you should use the SINGLELINE or DOTALL option, if you want your tags to span multiple lines.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.