212
Views
2
Comments
Regex_Search - my regex pattern isn't working as it does on an online regex tester
Question

I am using Regex_Search to match with keywords in a text and also include 4 words before and 4 words after the keyword.

it needs to match with keywords if it only matches part of the word as well for example: mpl would match example and 4 words before and after.

I am using (?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,4}(\w*|\s|^)keyword[a-zA-Z0-9]*(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,4} which works as shown on the regex tester here: https://regex101.com/r/dXGNbD/1/  but when using Regex_Search it doesnt match the rest of the word and the 4 words after, only 4 words before.

using the example from the link Regex_Search will only match "advances in pay, then comm" instead of "advances in pay, then communicate details of the benefits".


for context, this is being used to search through articles and to show a short preview of the article underneath containing where the search term has matched.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Luke,

I think you posted this question also on Stack overflow yesterday and I answered there yesterday too!

https://stackoverflow.com/questions/62636725/regex-for-searching-through-a-text-and-pick-out-4-words-beofre-and-4-words-after 

Regards,

Daniel


ps. For quickest answers and full community able to help always post OutSystems related questions on the OutSystems forum, not Stackoverflow.

UserImage.jpg
Luke Anthony

Daniël Kuhlmann wrote:

Hi Luke,

I think you posted this question also on Stack overflow yesterday and I answered there yesterday too!

https://stackoverflow.com/questions/62636725/regex-for-searching-through-a-text-and-pick-out-4-words-beofre-and-4-words-after 

Regards,

Daniel


ps. For quickest answers and full community able to help always post OutSystems related questions on the OutSystems forum, not Stackoverflow.

Oh ha, what a coincidence, that did help with getting it to work on the regex tester but when I put it into outsystems Regex_Search it doesn't work as it does on the tester. 

 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.