Question:
There is a DB from one table in which 3 fields: ID, an English word, translation.
For one of the tasks, I read only verbs using this expression (I have all the verbs that begin with the particle "To")
words = wordsfromDB.Where(w => w.EnglishWord.StartsWith("To")).ToList();
Now I want to implement the ability to read only phrasal verbs, that is, the value "To give" does not count, but the value "To give up" does.
That is, it must read all records that start with "To" and that have at least 3 words.
Help me set the right terms.
Answer:
Don't use regular expressions unless absolutely necessary. Both in pure SQL and in "LINQ to SQL", there is a LIKE
operator for such queries, which also allows you to filter by text patterns:
words = wordsfromDB.Where(w => SqlMethods.Like(w.EnglishWord, "To % up")).ToList();
It is executed an order of magnitude faster than "crutches" unusual for SQL with regular expressions.
And in general, on the task – look at full-text search. There are both extended text queries and grammatical-vocabulary cores, and not only for English.