Extract groups of numbers or characters from Text
A frequently occurring problem is how to extract groups of digits or characters from text.
We need a new function something like this:
- Extract groups of characters from a text-string
- Allow the user to define what constitutes a group of characters
- Extract the Nth group from the start, or the Nth group working backwards from the end
- Option to specify the maximum number of characters to extract from the front or the back of the group
- Option to give the start and/or end position within the string for the search for groups.
GROUPS(Text, GroupNumber, MaxChars, GroupType, StartPos, EndPos)
GroupNumber can be zero (all Groups) or a positive or negative number to get the Nth group from the start or end.
MaxChars can be zero (all characters) or a positive or negative number to restrict the number of characters from the start or end of the group.
GroupType can be either of
a Regex Pattern string, for example [0-9,.] would define a group as consecutive characters consisting of 0 to 9 comma and decimal point
A number from 0 to 4 for the most common group types (0-9 , a-z , not 0-9 , 0-9 and . , not 0-9 and .)
StartPos and EndPos default to the first character (1) and the last character (0)
My blog post on this is the third most popular post on my blog