Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A rather oversimplified example, but this should work. </p> <p>Note that the following will only allow alpha-numeric or '-' or '_' in the place you claim <em>(could be anything here)</em>. This is by nessesity if you intend to be able to recognize it with any form of parser regex or otherwise. You need to either limit the characters that can be used as an identifier, or you need to delineate them and allow for escaping the delimitation characters.</p> <pre><code>private static void Main() { Regex pattern = new Regex(@"(?&lt;Name&gt;[\w\-_]+)\.+(?&lt;Value&gt;[\w\-_]+)"); string sample = @"(123456789..value &gt; 2000) &amp;&amp; (987654321.Value &lt; 12)"; string result = pattern.Replace(sample, m =&gt; String.Format( "ClassName.GetInfo(\"{0}\").Get{1}{2}()", m.Groups["Name"].Value, Char.ToUpper(m.Groups["Value"].Value[0]), m.Groups["Value"].Value.Substring(1)) ); Console.WriteLine(result); } </code></pre> <p>The program outputs:</p> <blockquote> <blockquote> <p>(ClassName.GetInfo("123456789").GetValue() > 2000) &amp;&amp; (ClassName.GetInfo("987654321").GetValue() &lt; 12)</p> </blockquote> </blockquote> <p>There are two other rather odd behaviors in your example that are addressed above. The first is the use of multiple delimiters '..' in your example "(123456789..value". This seems like a possible mistake, just remove the '+' from this part of the expression ").+(".</p> <p>The second oddity is that your example just auto-magically corrects the character-case of the first property from "value" to "Value". Although I mimic this magical behavior by ensuring the first character is upper-case this is not a great solution. A better answer would be to use a case-insensitive dictionary and lookup the proper case.</p> <p>Hopefully that will get you started, but I have to be honest and say you have a VERY long road ahead of you. Parsing an expression language is never a trivial thing and should generally be avoided. If this is for internal use just make them type in the full version. If this is for external use... well, I would re-think you're objective. Perhaps building a graphical expression tree like SQL's QBE would be a better expenditure of your time and energy.</p>
 

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