Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The value for <code>input 2</code> can be a valid regular expression. All you need to do would be to add the <code>^</code> and <code>$</code> anchors, these will allow your regex engine to specifically match that pattern, so in your case, you could do something like so:</p> <pre><code> String input2 = "file*.xml"; Regex regex = new Regex("^" + input2.Replace(".", "\\.").Replace("*",".*") + "$"); String input1 = "file_123.xml"; String input3 = "file_123.xml.done"; System.Console.WriteLine(regex.IsMatch(input1)); System.Console.WriteLine(regex.IsMatch(input3)); System.Console.ReadLine(); ... </code></pre> <p>The <code>.</code> is a special character in regex so it needs to be escaped. The second <code>replace</code> statement adds a <code>.</code> which means any character infront of the <code>*</code> operator which means or or more repetitions of. The code above yields <code>True</code> and <code>False</code> respectively.</p> <p>EDIT: As pointed above, you will need to escape more characters depending on your scenario.</p> <p>EDIT 2: The code below should take care of escaping any string which is part of the regular expression language. In your case, this also means the <code>*</code> operator. I used the <code>Regex.Escape</code> method the escape all the characters which might have a special regex meaning and then used the usual <code>replace</code> to get the <code>*</code> back on track.</p> <pre><code> String input2 = "file*.xml"; input2 = Regex.Escape(input2); //Yields file\\*\\.xml input2 = input2.Replace("\\*", ".*"); //Yields file.*\\.xml Regex regex = new Regex("^" + input2 + "$"); String input1 = "file_123.xml"; String input3 = "file_123.xml.done"; System.Console.WriteLine(regex.IsMatch(input1)); System.Console.WriteLine(regex.IsMatch(input3)); System.Console.ReadLine(); </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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