Objective: Make the shortest function that splits a string at non-digits and returns an array consisting of only digits in each string, without the use of any regular expressions. Leading zeroes are to be included in each string.
Please read updated rule 2. It should clear up some of the mass of confusion. If you have any questions, please post them as a comment on this with `@impinball`.
Rules: (I apologize for the lengthiness)
- The format must be as a function with a single string argument. Up to two additional arguments may be added if necessary for the proper return of the array (e.g. sh/csh/DOS Batch needs an extra variable reference to return, etc.).
- The primary function declaration doesn't count, and nor does importing other standard libraries. `#include`s, `import`s, and `using`s don't count. Everything else does. This does include `#define`s and helper functions. Sorry for the confusion. Refer to this as a helpful guide as to what does/does not count (written in C-style syntax)
// doesn't count toward total, may be omitted unless // non-obvious, like half of Java's standard library. #include <stdio.h> import some.builtin.Class // doesn't count, see above #define printf p // counts towards total /* Any other preprocessor directives, etc. count. */ int i = 0; // counts someFunction(); // counts char[][] myMainSplitFunction(char[][] array) { // doesn't count // Everything in here counts return returnArray; // Even this counts. } // doesn't count /* Everything in here counts, including the declaration */ char[][] someHelperFunction(char[] string) { // stuff } // even this counts
- The output must be a string array or similar (Array lists in Java and similar are acceptable). Examples of accepted output:
String[]
,char[][]
,Array
,List
, andArray
(object). - The array must contain only contain variable-length string primitives or string objects. No empty strings should be present in the return, with the exception below. Note: the strings are to contain a string of consecutive matches, such as the example input and output below.
- If there are no matches, then the function body should return
null
, an empty array/list, or an array/list containing an empty string. - No external libraries allowed.
- DOS line endings count as one byte, not two (already covered in meta, but needs emphasized)
- And the biggest rule here: no regular expressions allowed.
This is a code-golf question, so smallest size wins. Good luck!
And here are some example inputs and outputs (with C-style escapes):
Input: "abc123def456" Output: ["123", "456"] Input: "aitew034snk582:3c" Output: ["034", "582", "3"] Input: "as5493tax54\\[email protected]" Output: ["5493", "54", "430", "52", "9"] Input: "sasprs]tore\"re\\forz" Output: null, [], [""], or similar
Please put how many bytes used by your answers, and as always, happy golfing!
EDIT: remove GolfScript restriction (forgot similar languages), clarify what is and isn't counted
EDIT: Hopefully rewriting rule 2 with a new guide should help clarify a lot of questions on what counts and what doesn't.