Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove text in-between delimiters in a string (using a regex?)
    primarykey
    data
    text
    <p>Consider the requirement to find a matched pair of set of characters, and remove any characters between them, <em>as well as</em> those characters/delimiters.</p> <p>Here are the sets of delimiters:</p> <pre class="lang-none prettyprint-override"><code> [] square brackets () parentheses "" double quotes '' single quotes </code></pre> <p>Here are some examples of strings that should match:</p> <pre class="lang-none prettyprint-override"><code> Given: Results In: ------------------------------------------- Hello "some" World Hello World Give [Me Some] Purple Give Purple Have Fifteen (Lunch Today) Have Fifteen Have 'a good'day Have day </code></pre> <p>And some examples of strings that should not match:</p> <pre class="lang-none prettyprint-override"><code> Does Not Match: ------------------ Hello "world Brown]co[w Cheese'factory </code></pre> <p>If the given string doesn't contain a matching set of delimiters, it isn't modified. The input string may have many matching pairs of delimiters. If a set of 2 delimiters are overlapping (i.e. <code>he[llo "worl]d"</code>), that'd be an edge case that we can ignore here.</p> <p>The algorithm would look something like this:</p> <pre><code>string myInput = "Give [Me Some] Purple (And More) Elephants"; string pattern; //some pattern string output = Regex.Replace(myInput, pattern, string.Empty); </code></pre> <p><strong>Question:</strong> How would you achieve this with C#? I am leaning towards a regex. </p> <p><strong>Bonus:</strong> Are there easy ways of matching those start and end delimiters in constants or in a list of some kind? The solution I am looking for would be easy to change the delimiters in case the business analysts come up with new sets of delimiters.</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.
    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