![]() * equivalent regular expression metacharacters. * Replace the SQL LIKE wildcard metacharacters with the accounting for cases such as LIKE '%abc' or LIKE 'abc%'īool startsWith = pattern.StartsWith("%") & !pattern.EndsWith("%") īool endsWith = !pattern.StartsWith("%") & pattern.EndsWith("%") īuilder.Replace("%", "", pattern.Length - 1, 1) *? replacement below at the begining or end of the string is not StringBuilder builder = new StringBuilder(Regex.Escape(pattern)) Turn "off" all regular expression related syntax in the pattern string. Here is my code: internal static string ConvertLikeToRegex(string pattern) I've amended the conversion algorithm to account for starts with and ends with LIKE expressions. ![]() *?abc is capturing both "abcdef" and "123abcdef". ![]() This conversion replaces all "%" with ".*?" which works for contains patterns but is over matching for starts with or ends with patterns. For some time I have been using this conversion. I have a bit of code that converts a Sql Like expression to a regex expression for the purposes of a Linq to objects Like extension method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |