I try to split a text with preg_split, but I dont get the regrex for it.
example:
I search 1, regex to: no. Or... yes!
should get:
Array
(
[0] => I
[1] => search
[2] => 1
[3] => ,
[4] => regex
[5] => to
[6] => :
[7] => no
[8] => .
[9] => Or
[10] => ...
[11] => yes
[12] => !
)
I tryd the following code:
preg_split("/([\s]+)/", "I search 1, regex to: no. Or... yes!")
which end in:
Array
(
[0] => I
[1] => search
[2] => 1,
[3] => regex
[4] => to:
[5] => no.
[6] => Or...
[7] => yes!
)
EDIT: Ok, the original question was solved, but I forgot something in my example:
new example:
I search 1, regex (regular expression) to: That's it is! Und über den Wolken müssen wir...
should get:
array (
0 => 'I',
1 => 'search',
2 => '1',
3 => ',',
4 => 'regex',
5 => '(',
6 => 'regular',
7 => 'expression',
8 => ')',
9 => 'to',
10 => ':',
11 => 'That',
12 => '\'s',
13 => 'it',
14 => 'is',
15 => '!',
16 => 'Und',
17 => 'über',
18 => 'den',
19 => 'Wolken',
20 => 'müssen',
21 => 'wir',
22 => '...',
)
one thing is, that the opening ( get not matched in the first solution. A other thing is, that also not the german chars ÄÖÜäöüß inside a word get not matched.
Hope its ok to update the question (not to open a new one).
My last try was the following, which dont match:
\s+|(?<!(A-Za-z1-0ÄÖÜäöüß)+)(?=(A-Za-z1-0ÄÖÜäöüß)+)