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 6735851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:03:41+00:00 2026-05-26T11:03:41+00:00

How can I achieve the following using Regex/c# replace? Input string I have :

  • 0

How can I achieve the following using Regex/c# replace?

Input string I have : ” test data : <test param="p" value="v"/> input string continues”

Output string I need : ” test data : ((test param={p} value={v})) input string continues “

  • 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-26T11:03:41+00:00Added an answer on May 26, 2026 at 11:03 am

    I assume your real question is HOW to achieve it, and find/replace requirements seem to be fairly rigid, here is one that works for your case:

    Find:      ([^:]*): <([^=]*)="([^"])"([^=]*)="([^"])"/>
    Replace:   $1: (($2={$3}$4={$5}))
    

    The Find expression can be broken down like this:

    ([^:]*)    # Capture zero or more characters that ARE NOT a colon
    : <        # Match a colon, a literal space, then a less-than sign
    ([^=]*)    # Capture zero or more characters that ARE NOT an equals sign
    ="         # Match an equals sign, then a double quote
    ([^"])     # Capture zero or more characters that ARE NOT a double quote
    "          # Match a double quote
    ([^=]*)    # Capture zero or more characters that ARE NOT an equals sign
    ="         # Match an equals sign, then a double quote
    ([^"])     # Capture zero or more characters that ARE NOT a double quote
    "/>        # Match a double quote, a forward slash, then a greater-than sign
    

    The parentheses () in the regex mean to “capture” any characters matched by the contents of the parentheses. Anything not in parentheses will be “matched”, but will be discarded during a find and replace. This is useful for extracting bits of data from a pattern like extracting name, attribute1 and value1 from <name attribute1="value1"/> to then put into another pattern of text.

    In C#, you use the System.Text.RegularExpressions.Regex object to match or to replace using regular expressions. I believe the syntax/signature (for an instance of the Regex object) is regexObject.Replace(input As String, replacement As String) As String

    The replacement expression contains $1, $2, etc, which refer to the parts of the match enclosed in parantheses (). Thus, $1 (in the replacement expression) will insert the text matched by the first group ([^:]*) (from the match expression)

    This combination will turn this text:

    “test data : <test param=”p” value=”v”/>” more text. blah blah blah “test data : <test param=”p” value=”v”/>” and then some more text…

    Into this text:

    “test data : ((test param={p} value={v}))” more text. blah blah blah “test data : ((test param={p} value={v}))” and then some more text…

    A great resource for learning about Regexes (and where I learned about 90% of what I know) is Regular-Expressions.info, and an associated tool called RegexBuddy is great for constructing, testing, and debugging regexes as well.

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

Sidebar

Related Questions

As the title says, how can I achieve the following in ruby using regex
How can I achieve the following? I have two models (blogs and readers) and
How can I achieve the following with a format string: Do 01.01.2009 ? It
How can I achieve the following in oracle without creating a stored procedure? Data
I want a rich text box control using which i can achieve following functionality:
I would like to know how I can achieve the following using the nginx
How can I achieve the following structure without using tables or JavaScript? The white
I have the following code : using System.Collections.Generic; public class Test { static void
In a htmlpage using jQuery or JavaScript how can the following be achieved? User
Does anyone know how I can achieve the following effect in OpenGL: Change the

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.