Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are going to use regex I wouldn't use a helper "GetTextBetween" function. I would just write one regex per situation. But, if you do you want to use this there will be some issues with special characters (since for leftString and rightString you want to find them exactly and not have any special symbols in them be treated as part of a regular expression. ) leftWord and rightWord will need to escape some characters for regular expressions. I use something like this: </p> <pre><code> private static string EscapeCharsForRegularExpression( string s ) { //note that we must replace the \ first, because the following statements add backslashes return s.Replace( "\\", "\\\\" ).Replace( ".", "\\." ).Replace( "(", "\\(" ).Replace( ")", "\\)" ).Replace( "&lt;", "\\&lt;" ).Replace( "[", "\\[" ).Replace( "]", "\\]" ).Replace( "&gt;", "\\&gt;" ).Replace( "{", "\\{" ).Replace( "}", "\\}" ).Replace( "*", "\\*" ).Replace( "^", "\\^" ).Replace( "+", "\\+" ).Replace( ":", "\\:" ); } </code></pre> <p>You could probably cleanup a lot of my use of double slashes by putting doing stuff like:</p> <pre><code>@"\[" etc. </code></pre> <p>Oh ... and this regex gives you your first match:</p> <pre><code>Regex.Matches( inputString, @"&lt;!--\s*(.+?)\s*--&gt;", RegexOptions.None )[0].Groups[1].Value; </code></pre> <p>For: 'div-gpt-ad-1383121038726-0'</p> <pre><code>Regex.Matches( inputString, @"'.*?'", RegexOptions.None )[0].Groups[0].Value; </code></pre> <p>For: div-gpt-ad-1383121038726-0 (without apostrophes around it)</p> <pre><code>Regex.Matches( inputString, @"'(.*?)'", RegexOptions.None )[0].Groups[1].Value; </code></pre>
 

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