Forum Moderators: coopster
How do I
(a) get the number 123 off as a separate variable.
(b) how do I separate the some more text ..... bit without the buffer.
I am making no progress with this at all.
preg_match("/[0-9]/", $variable);
$numextracted=$matches[0];
Gets me nowhere with (a);
and
for (b)
$separatedbit = preg_replace ("/^[0-9]+/","",$variable);
Gets the numbers off at the begining when there are 2 numbers but does nothing when there is a single digit.
I seem to be managing fine with the rest of PHP it is just the wretched reg exps that are giving me the problem.
Everything always seems to work with Perl for me.
Perhaps it is because I feel like I may be coming down with a bout of flu.
$variable = "123buffersome more text that may have numbers in it.";
// preg_match("/[0-9]/", $variable); // <-- forgot matches parameter!
preg_match("/[0-9]+/", $variable, $matches);
$numextracted=$matches[0];
This is the trouble when you are new at something. It is more easy to assume that you are not doing something that is rather complicated in the correct manner than to assume there is a simpler problem elsewhere.
It is not related to the previous posting except that I learned the method I am using from there and thus there is a similarity.
The word buffer is there to be discarded. Essentially what I am doing is sorting some randomly sorted but numbered data. The easiest way is to tag the numbers on the beginning and do a natsort() on the array.
The word buffer is there to distinguish between
1 2this is the string
and
12 this is the string
which become
1buffer2this is the string
and
12bufferthis is the string.
I have it all working as I want now.