Extract the first N words
- 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
Hi all- I am trying to design a marco that can help users to extract the first N words. But struggle with the REGEX here. In my example below, I have "(^(?:\S+\s+\n?){1,3})" so it should show the first 3 words, but instead it will only show the first 2 words. Any idea why? I attached the workflow below. Thanks!
Solved! Go to Solution.
- Labels:
- Common Use Cases
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This is a fun one for sure! The RegEx statement is returning:
A string of one or more non-whitespace characters FOLLOWED BY a string of one or more whitespace characters POTENTIALLY FOLLOWED BY a newline character.
The final character for the final word is not a space, therefore the RegEx is not capturing that last word.
I'm sure there are many solutions to this, but one solution is the below RegEx that removes the necessity for a capture word to end with a space by allowing 0 or more spaces following the non-whitespace characters.
(^(?:\S+\s*\n?){1,3})
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here's a creative way to do it
- Address a RecordID to each row
- Use Tokenize REGEX to split words using the expression (\b\w+\b)
- Use Sample Tool and apply your numeric drop down to change how many words you want.
- Group by RecordID and concatenate separating by spaces (\s)
- Drop the RecordID field
This is just one way without complicating it too much (it uses more tools, but it's simple to understand)
WF attached.
Cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This looks like it was an awesome macro project! A very simple approach may have just been to use the GetWord(String, 1) and applied this to all value. The Macro could be then enable to dynamically update the number of words required. Just posting here in case other communities members find this helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator