This is a very fun problem and I'm getting giddy 🙂
There's lots of requirements here. Let me share a big idea and I'd love it if @LRVinNC @RandyHayes @v-xida-msft can add more to the formula and their take.
Big idea: I can Split() a string of text so that each character is its own row in a table.
Split("123abc","")
This formula would return a table of 6 records. It would have a column called "Result" that would contain the individual character that had been split: 1, 2, 3, a, b, c. Here the delimiter is "" which indicates split every individual character.
Now that each character is in a table, you could do many things. You could filter the table where each row matches certain criteria. IsMatch can check if something is a digit or a letter, etc. You could count how many characters fit the criteria.
Then after you filter the rows you want, you could concatenate the filtered set again. Maybe you had wanted to filter out all the digits into one table. You can concatenate that subset again, convert them to a value, and format them to include leading zeroes.
Text(Value(Concat(Filter(Split("123abc",""),IsMatch(Result,Digit)),Result)),"0000")
There's a few parts to this one. Reading inside out--some Excel work 🙂
- Split: described earlier
- Filter: filters the characters to return only characters that are digits
- Concat: collapses the table into a string again
- Value: makes the digits into numbers (since they had been concatenated, they are strings)
- Text: same formula @LRVinNC shared earlier
Next you could append the filtered characters that were not digits and run through a similar process.