Is there a way to declare preference in a regular expression?
For example assume I have the following terms to search:
cat eats mouse
And I have the following text:
I saw yesterday a big mouse in our house. Why? We have a cat!A cat eats mouse.Right?
I want a regular expression that matches the section specifically the section A cat eats mouse.
I.e. although the terms exist in other parts, that sentence is a better match i.e. it is prefered.
But if this part was missing it would have matched the I saw yesterday a big mouse in our house. Or We have a cat.
Can this be expressed in a regular expression?
No, regex isn’t the right tool for this.
You can use a regex (though a plain substring search might be more appropriate) to find each of the words you’re looking for, and assign weights to the matches (based number of occurrence of each term, appearance of all terms, relative order of the terms…) outside the regex.
But your end goal is too fuzzy, not regular enough – you’ll need more than just regular expressions.