I'm trying to build a macro that will capture information before and after a specific keyword on a clipboard.
For example, if I copy to a clipboard the following text:
The rain in Spain falls mainly on the plain. If I designate the keyword "Spain", I'd like to return the result on either the clipboard or variable, "...rain in Spain falls mainly..." So, two words before and two words after the keyword. If anyone can help me with this type of filter, I'd greatly appreciate it!
These all work flawlessly! As a follow up, I will be storing my keyword as a variable as it may change. In that case, can I simply reference the variable in the RegEx string? For example, instead of writing "Spain", I'll have %variable%keyword%.
One final question: let's say I get the result "rain in Spain falls mainly" But in a particular instance, the sentence ends at falls. So the result would be "rain in Spain falls. mainly". Is there a simple way to just limit the results right at the period, instead of including "mainly".
Parsing text is an exacting business – especially when you're tying to accommodate different possible inputs.
In a case like this the smart thing to do is generally let go of the idea of writing the perfect regular expression and preprocess the text with a different regex.
Something like this which will remove all text from a period to the end of the string.