Extract N words in a string before and after a certain word
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello.
I have a long text containing several instances of the word "credible". For example: sentence 1. sentence2 that contains the word credible. sentence 3. sentence4 that contains the word credible. sentence5 that contains the word credible. sentence6. sentence7. etc,,,,
I want to be able to output a new column that contains 30 words or 100 characters before the word "credible"+ the word credible+ 30 words or 100 characters after the word "credible". In the example above, I will have 3 columns.
I tried RegEx with the expression credible\s+\w+ but getting only the word credible+ 1 word after. The setting is that the output tokenize 20 columns. I am new to RegEx.
Appreciate your help.
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
To get part of the way there, you might try replacing credible with "|credible|",
replace([my_field], 'Credible', '|credible|')
And then use a text to columns.
Feel free to send an example of the input and output you expect if you're having difficulties thereafter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you. Partially worked with replace. I ended up using (?:\S+\s+){0,30}\bcredible\b(?:\s+\S+){0,30} and that worked much better. Thank you all.
