1

I have a couple of strings. These are (examples)

  Phone 12345 aa / bb
  Phone is 12345 aa / bb
  Phone is this 12354 aa / bb

I've tried to find a regular expression that allows me to use string.split(regex) function on android / java, but I have not found any that actually does the trick.

What I want is the string to be split on the whitespace before the phonenumber. In the list below, [1] is what gets returned before the whitespace and [2] is what is left.

  [1]Phone[2]12345 aa / bb
  [1]Phone is[2]12345 aa / bb
  [1]Phone is this[2]12354 aa / bb

Most of my feeble attemts removes the first digit (1) in 12345.

Can anyone help me?

4

2 に答える 2

2

try this:

String[] arr  = str.split(" (?=\\d)");
于 2013-03-11T20:56:44.520 に答える
1

Use this RegEx Pattern: \s+(?=\d)

Explained demo here: http://regex101.com/r/jY9eO4

It works because it doesn't capture the digit just 'Looks Ahead' to see if there is one.

于 2013-03-11T20:55:51.443 に答える