Search code examples
c#.netregexexpression-trees

C# library for human readable pattern matching?


Does anybody know a C# library for matching human readable patterns? Similar to regex, but friendlier?

Given a string value, I want to be able to match it against a pattern along the lines of:

(this AND that) OR "theother"

where "this" and "that" are LIKE expressions, and "theother" is an exact match due to the quotes.

UPDATE: Ok, just to be a little bit clearer. The reason I want this is to allow end users to enter in their own patterns, as string values. So I'm after something that works in a similar way to regex, but uses human readable strings that my users will easily understand

var pattern = "(this AND that) OR \"theother\""; // Could be fetched from textbox
var match = SomeLib.IsMatch(myString, pattern);

Solution

  • Well, after a lot of searching, I wasn't able to find exactly what I was after, but needing to get something working pretty quickly, and due to the fact the system I'm using already has the relevant DLLs, I've ended up using Lucene.NET to created a temporary index containing a single document with the relevant fields I need to search added to it. I can then do the type of query I'm after against it, and check for any matches. By using the RAMDirectory class I was able to create the index in memory, and dispose of it after the lookup, so no index files have to be written to disk.

    I'm sure there are probably less intensive ways to achieve this, but as I say, it's the best I could come up with in the time I had.

    Thank to everyone for their suggestions, and I would still like to know if there is a better way of doing this?