Get numbers from string with regex

前端 未结 5 1990
Happy的楠姐
Happy的楠姐 2020-12-07 00:27

I am trying to write a regex to get the numbers from strings like these ones:

javascript:ShowPage(\'6009\',null,null,null,null,null,null,null)
javascript:Bloc         


        
5条回答
  •  北海茫月
    2020-12-07 01:29

    // PHP
    
    $string = 'ssss 12.2';
    $pattern = '/\D*(\d+)(.|,)?(\d+)?\D*/';
    
    $replacement = '$1.$3';
    
    $res = (float)preg_replace($pattern, $replacement, $string);
    
    // output 12.2
    

提交回复
热议问题