Would anyone want to help me with a regex to reliably recognize and remove any number followed by a dot at the beginning of a line? So that
1. Introduction
becomes
Introduction
and
1290394958595. Appendix A
Appendix A
Try:
preg_replace('/^[0-9]+\. +/', '', $string);
What gives:
php > print_r(preg_replace('/^[0-9]+\. +/', '', '1231241. dfg')); dfg
I know the question is closed, only my two cents:
preg_replace("/^[0-9\\.\\s]+/", "", "1234. Appendix A");
It’s best to work, in my opinion, mainly because it will also handle cases like
1.2 This is a level-two heading
:
^[0-9]+\.
, , , , . , .
// 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. ');
, .
$string = "1290394958595. Appendix A"; $first_space_position = strpos(" ", $string); $stuff_after_space = substr($string, $first_space_position);
$string = "1290394958595. Appendix A"; $first_dot_position = strpos(".", $string); $stuff_after_dot = substr($string, $first_dot_position);
/[0-9]+\./
Btw, I would definitely use regex here, since they are very reliable and light.
Greetings
print preg_replace('%^(\d+\. )%', '', '1290394958595. Appendix A');
PHP function to find a string for regular expression and replace it with something else preg_replace. In this case, you want something like:
preg_replace
$mytitle = preg_replace('/^[0-9]+\. */', '', $myline);
$str="1290394958595. Appendix A"; $s = explode(" ",$str,2); if( $s[0] + 0 == $s[0]){ print $s[1]; }
Source: https://habr.com/ru/post/1735835/More articles:Good Flex book for long time developers - flexHow to handle IllegalStateException code in Cursor? - androidA way to find out if a WCF service is called via HTTP or HTTPS? - wcfHow to make Pylons work in Google App Engine? - google-app-engineЛучший плагин слайдшоу jQuery с элементами паузы/воспроизведения/next/prev? - javascriptAndroid Style ListView - androidPageAsyncTask Page Examples (Asynchronous asp.net Pages) - asp.netConflict between a system call number and a system call handler pointer - linuxUpload file to ColdFusion database - coldfusioniPhone POST with PHP error - phpAll Articles