Reputation: 21
For some reason, I want to remove the leftmost number inside the whole string. Here are the example:
Is it possible do in php?
I tried to use:
$words = preg_replace('/[0-9]+[a-z]/', '', $file);
but it will remove both the number and the first alphabet.
Upvotes: 0
Views: 45
Reputation:
and if you dont like Rizier123 aswer:
$words = ltrim('123ab1ab123','0123456789');
or
$words = ltrim('123ab1ab123','0..9');
trims all numbers from left, probably faster than are regular expression also
Upvotes: 2
Reputation: 59701
You can just use an anchor and remove the [a-z]
part from your regex:
$words = preg_replace('/^[0-9]+/', '', $file);
Upvotes: 4