I want to write a regex with statements to extract the number 55 from the string unknownstring/55.1 , here is my regex
$str = 'unknownstring/55.1'; preg_match('/(?<=\/)\d+(?=\.1)$/', $str, $match);
so basically I'm trying to say to give me the number that appears after the slash, followed by a period and number 1, and after that there are no characters. But this does not match the regular expression. I just tried removing the $ sign from the end and it matched. But this condition is important, since I need it to be the end of the line, because the unknownstring part may contain similar text, for example. unknow/545.1nstring/55.1 . Maybe I can use preg_match_all and take the last match, but I want to understand why the first regular expression does not work, where is my error.
thanks
source share