Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace any string between quotes
    primarykey
    data
    text
    <p><strong>Problem:</strong></p> <p>Cannot find a consistent way to replace a random string between quotes with a specific string I want. Any help would be greatly appreciated. </p> <p><strong>Example:</strong></p> <pre><code>String str1 = "test=\"-1\""; </code></pre> <p>should become</p> <pre><code>String str2 = "test=\"31\""; </code></pre> <p>but also work for</p> <pre><code>String str3 = "test=\"foobar\""; </code></pre> <p>basically I want to turn this</p> <pre><code>String str4 = "test=\"antyhingCanGoHere\""; </code></pre> <p>into this</p> <pre><code>String str4 = "test=\"31\""; </code></pre> <p><strong>Have tried:</strong></p> <p><a href="https://stackoverflow.com/questions/2439965/case-insensitive-regex-without-using-regexoptions-enumeration">Case insensitive Regex without using RegexOptions enumeration</a></p> <p><a href="https://stackoverflow.com/questions/1139439/how-do-you-do-case-insensitive-string-replacement-using-regular-expressions">How do you do case-insensitive string replacement using regular expressions?</a> </p> <p><a href="https://stackoverflow.com/questions/6530123/replace-any-character-in-between-anytext-and-usernameredactedexample-com-wit">Replace any character in between AnyText: and &lt;usernameredacted@example.com&gt; with an empty string using Regex?</a> </p> <p><a href="https://stackoverflow.com/questions/7564725/replace-string-in-between-occurrences">Replace string in between occurrences</a></p> <p><a href="https://stackoverflow.com/questions/10403639/replace-a-string-between-two-strings">Replace a String between two Strings</a></p> <p><strong>Current code:</strong></p> <pre><code> Regex RemoveName = new Regex("(?VARIABLE=\").*(?=\")", RegexOptions.IgnoreCase); String convertSeccons = RemoveName.Replace(ruleFixed, "31"); </code></pre> <p><strong>Returns error:</strong></p> <pre><code>System.ArgumentException was caught Message=parsing "(?VARIABLE=").*(?=")" - Unrecognized grouping construct. Source=System StackTrace: at System.Text.RegularExpressions.RegexParser.ScanGroupOpen() at System.Text.RegularExpressions.RegexParser.ScanRegex() at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op) at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, Boolean useCache) at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options) at application.application.insertGroupID(String rule) in C:\Users\winserv8\Documents\Visual Studio 2010\Projects\application\application\MainFormLauncher.cs:line 298 at application.application.xmlqueryDB(String xmlSaveLocation, TextWriter tw, String ruleName) in C:\Users\winserv8\Documents\Visual Studio 2010\Projects\application\application\MainFormLauncher.cs:line 250 InnerException: </code></pre> <p><strong>found answer</strong></p> <pre><code>string s = Regex.Replace(ruleFixed, "VARIABLE=\"(.*)\"", "VARIABLE=\"31\""); ruleFixed = s; </code></pre> <p>I found this code sample at Replace any character in between AnyText: and with an empty string using Regex? which is one of the links i previously posted and just had skipped over this syntax because i thought it wouldnt handle what i needed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload