C# library for human readable pattern matching?

.net c# expression-trees regex

Question

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);

Accepted Answer

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?


Popular Answer

I read this article a while back. It sounds along the lines of what you are asking.

Readable Regular Expressions

Which, looking at your request, you would then need to create a mapping of 'user friendly' terminology and this library's fluent interface.

It's an extra layer of abstraction, true but I personally, would rather read a fluent 'intermediate stage' than auto generated regex :s




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why