Splitting a string containing letters and numbers not separated by any particular separator in PHP

I am currently developing a web application to extract the Twitter stream and attempt to independently create natural language processing.

Since my data is taken from Twitter (limited to 140 characters), many words have been reduced, or in this case, the missed space .

For instance:

"Hi, my name is Bob. I m 19yo and 170cm tall"

Must be designated as:

- hi
- my
- name
- bob
- i
- 19
- yo
- 170
- cm
- tall

Note that 19both yoin 19yohave a space between them. I use it mainly to extract numbers with their units.

Just what I need is a way to β€œexplode” every token that has a number in it with numbers or letters without .

'123abc' will be ['123', 'abc']

'abc123' will be ['abc', '123']

'abc123xyz' will be ['abc', '123', 'xyz']

etc.

PHP?


- , # spesifically /. #

+5
2

preg_split

$string = "Hi, my name is Bob. I m 19yo and 170cm tall";
$parts = preg_split("/(,?\s+)|((?<=[a-z])(?=\d))|((?<=\d)(?=[a-z]))/i", $string);
var_dump ($parts);

- . . .

http://codepad.org/i4Y6r6VS

+7

:

, , , "" . , , .

, imho .

EDIT: , , . ( , )

<?php
$str = "Hi, my name is Bob. I m 19yo and 170cm tall";
preg_match_all("#\d+#", $str, $matches);
$str = preg_replace("!\d+!", "#SPEC#", $str);

print_r($matches[0]);
print $str;
+1

All Articles