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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:01:37+00:00 2026-06-10T16:01:37+00:00

Is there a way to do a replace in a string like this? (this

  • 0

Is there a way to do a replace in a string like this? (this is simplified example)

string input = "INSERT INTO blah VALUES \" blah blah \r\n \" \r\n (here can be anything like several new lines and \t tabs) INSERT INTO blah VALUES \" blah blah \r\n \" \r\n";

input.Replace("\r\n", "\n"); // this is just example, it doesn't work the way I need it

// and the output would look like this:
string output= "INSERT INTO blah VALUES \" blah blah \r\n \" \n INSERT INTO blah VALUES \" blah blah \r\n \" \n";

So it would replace new lines only outside the SQL commands? Can this be safely achieved using regular expressions?

EDIT: the replace must be probably realised with \r\n to \n there could be more of them between the SQL commands. The commands are not precisely separated.

EDIT: so the basic problem is – how do I replace in the outer string only?

string = "outer string \"inner string\" outer string \"inner string\" outer string"
  • 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-10T16:01:39+00:00Added an answer on June 10, 2026 at 4:01 pm

    Do you want something like this….

    /// <summary>
    ///  Regular expression built for C# on: Wed, Aug 29, 2012, 09:56:25 AM
    ///  Using Expresso Version: 3.0.4334, http://www.ultrapico.com
    ///  
    ///  A description of the regular expression:
    ///  
    ///  [1]: A numbered capture group. [(?<counter>").*?(?<-counter>").*?(?(counter)(?!))]
    ///      (?<counter>").*?(?<-counter>").*?(?(counter)(?!))
    ///          [counter]: A named capture group. ["]
    ///              "
    ///          Any character, any number of repetitions, as few as possible
    ///          Balancing group. Remove the most recent [counter] capture from the stack. ["]
    ///              "
    ///          Any character, any number of repetitions, as few as possible
    ///          Conditional Expression with "Yes" clause only
    ///              Did the capture named [counter] match?
    ///              If yes, search for [(?!)]
    ///                  Match if suffix is absent. []
    ///                      NULL
    ///  \r\n
    ///      Carriage return
    ///      New line
    ///  
    ///
    /// </summary>
    Regex regex = new Regex(
          "((?<counter>\").*?(?<-counter>\").*?(?(counter)(?!)))\\r\\n",
        RegexOptions.CultureInvariant
        | RegexOptions.Compiled
        | RegexOptions.Singleline
        );
    
    string input = "INSERT INTO blah VALUES \" blah blah \r\n \" \r\n (here can be anything like several new lines and \t tabs) INSERT INTO blah VALUES \" blah blah \r\n \" \r\n";
    
    string output output=regex.Replace(input,"$1\n");
    

    The effect of (?<counter>").*?(?<-counter>").*?(?(counter)(?!)) is to match only balancing " characters so to only find the \r\n outside the quotes

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

Sidebar

Related Questions

I want to replace some chars with accents in a String like this example:
Is there a way to search in a database a custom string and replace
Is there a lazy way I can quickly replace all instances of a word
Is there a way to sort a List<T> using a string like Name desc
Is there a way to run a regexp-string replace on the current line in
Example: I have some text, like this php code if(empty($condition)) { // work here...
Is there a way to do case insensitive replace on a string without using
Say I have a string like this some3random5string8 I want to insert spaces after
there is a string like this and it is stored in a file #{date}abcde.doc
Is there a quick way in Python to replace strings but, instead of starting

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.