Would somebody care to help me out with a regex to reliably recognize and remove any number, followed by a dot, in the beginning of a string? So that
1. Introduction
becomes
Introduction
and
1290394958595. Appendix A
becomes
Appendix A
Try:
preg_replace('/^[0-9]+\. +/', '', $string);
Which gives:
php > print_r(preg_replace('/^[0-9]+\. +/', '', '1231241. dfg'));
dfg
I know the question is closed, just my two cents:
preg_replace("/^[0-9\\.\\s]+/", "", "1234. Appendix A");
Would work best, in my opinion, mainly because It will also handle cases such as
1.2 This is a level-two heading
Voilà:
^[0-9]+\.
Ok, this does not qualify for recognize and remove any number, followed by a dot, but it will return the desired string, e.g. Appendix A, so it might qualify as an alternative.
// remove everything before first space
echo trim(strstr('1290394958595. Appendix A', ' '));
// remove all numbers and dot and space from the left side of string
echo ltrim('1290394958595. Appendix A', '0123456789. ');
Just disregard it, it it's not an option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With