I want next and previous word of which I searched with REGEX that I can get with pattern as below.
In this case I have searched word "the", So I can get next and previous word of "the". That I can get successfully with following pattern.
'\\b(?=(\\w+\\s+the|the\\s+\\w+)\\b)'
But with this pattern, I am having one issue is when searched word is first in page ("cite" in case of below sample text) or last ("attachments" in case of below sample text) it won't find it.
Sample Text
cite any cases or other legal materials that the arbitrator should read before the hearing attachments
I also getting first and last word but with different pattern. Pattern when searched word is first in page.
For First word
'\\b(?=($+cite|cite\\s+\\w+)\\b)'
For last word
'\\b(?=(\\w+\\s+attachments|attachments+$)\\b)'
I want all these three possibilities with single pattern weather word is first or last or in middle.
Have tested with changing combination, But not successfully.
Can anyone help me please to get all these in one pattern like it should give results for next/previous words?