Reputation: 21
Using OutSystems i need a Regex for searching through a text and pick out 4 words before and 4 words after the search term.
I am currently using (?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,4}(\w+|\s|^)keyword[a-zA-Z0-9]*(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,4}
it needs to match words even if the keyword only matches part of a word in the text. for example if my keyword was mpa and the text contained "here at my random company for example purposes we" it would match that string. this works.
Where im getting an issue with my current expression is if you do match a complete word, it doesn't get the 4 words beforehand. for example using the same text as above but with keyword company it would only match " company for example purposes we"
I hope that makes sense
Upvotes: 1
Views: 1096
Reputation: 21
Not really an OutSystems question, but more a RegEx related question.
Try this (use w*
instead of w+
) :
(?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,4}(\w*|\s|^)keyword[a-zA-Z0-9]*(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,4}
Upvotes: 2