Regular expression to split string and number

I know you asked for the Split method, but as an alternative you could use named capturing groups: var numAlpha = new Regex(“(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)”); var match = numAlpha.Match(“codename123”); var alpha = match.Groups[“Alpha”].Value; var num = match.Groups[“Numeric”].Value;

Split string into repeated characters

Try this: String str = “aaaabbbccccaaddddcfggghhhh”; String[] out = str.split(“(?<=(.))(?!\\1)”); System.out.println(Arrays.toString(out)); => [aaaa, bbb, cccc, aa, dddd, c, f, ggg, hhhh] Explanation: we want to split the string at groups of same chars, so we need to find out the “boundary” between each group. I’m using Java’s syntax for positive look-behind to pick the previous … Read more

How to split a string by a string in Scala

The REPL is even easier than Stack Overflow. I just pasted your example as is. Welcome to Scala version 2.8.1.final (Java HotSpot Server VM, Java 1.6.0_22). Type in expressions to have them evaluated. Type :help for more information. scala> “string1::string2”.split(“::”) res0: Array[java.lang.String] = Array(string1, string2)

Split strings in tuples into columns, in Pandas

And for the other case, assuming it are strings that look like tuples: In [74]: df[‘stats’].str[1:-1].str.split(‘,’, expand=True).astype(float) Out[74]: 0 1 2 3 4 0 -0.009242 0.410000 -0.742016 0.003683 0.002517 1 0.041154 0.318231 0.758717 0.002640 0.010654 2 -0.014435 0.168438 -0.808703 0.000817 0.003166 3 0.034346 0.288731 0.950845 0.000001 0.003373 4 0.009052 0.151031 0.670257 0.012179 0.003022 5 -0.004797 … Read more

Why does str.split not take keyword arguments?

See this bug and its superseder. str.split() is a native function in CPython, and as such exhibits the behavior described here: CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot be supplied by keyword. … Read more