C# library for pattern matching that is user readable?

.net c# expression-trees regex


Does anybody know of a C# library that matches patterns in human readable form? Regex-like, but friendlier?

I want to be able to compare a string value to a pattern that looks like this:

(this AND that) OR "theother"

where "this" and "that" are phrases that are LIKE each other, and "theother" is a perfect match because of the quotations.

UPDATE: Okay, let me try to be a little more explicit. Allowing end users to add their own patterns as string values is the main reason I want this. Therefore, I'm looking for something that operates similarly to regex but makes use of clearly understood human readable strings.

var pattern = "(this AND that) OR \"theother\""; // Could be fetched from textbox
var match = SomeLib.IsMatch(myString, pattern);
3/25/2011 1:46:56 PM

Accepted Answer

However, since I needed to get something working quickly and the system I'm using already has the necessary DLLs, I ended up using Lucene.NET to create a temporary index that contained a single document with the relevant fields I needed to search added to it. Unfortunately, despite my best efforts, I was unable to find exactly what I was looking for. I can then run the search against it to see if there are any matches. I was able to generate the index in memory and delete it after the search by utilizing the RAMDirectory class, eliminating the need to save index files to disk.

There may be less time-consuming methods to do this, but like I said, it's the best I could do with the time I had.

I appreciate everyone's advice, but I'm still curious whether there's a better way to go about this.

3/25/2011 7:08:23 PM

Popular Answer

I recently read this article. It seems to be in accordance with your inquiry.

Regular Expressions that are readable

Considering your requirement, you would then need to develop a mapping between "user pleasant" terms and the fluid interface of this library.

Although there is an additional layer of abstraction, I would much prefer read a fluent "intermediate stage" than automatically created regex:s.

Related Questions

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow