Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Explode from first number (integer)

I want to explode some test with first number (integer) in it . Here are some words .

Avant Browser 2013 Build 110

Firefox 23.0 Beta 10

Google Chrome 29.0.1547.41 Beta

i am trying this but its not working.

$in ='Avant Browser 2013 Build 110';

preg_match("/\d[^A-Za-z]+([A-Za-z\s]+)/", $in, $match);

echo $match[0];

Output needed is :-

Avant Browser

Firefox

Google Chrome

Please help

like image 547
Harinder Avatar asked Apr 12 '26 12:04

Harinder


2 Answers

Try this regex:

^.*?(?=\d)    //start lookup from linestart, get all symbols before first number occurance
like image 128
Sergio Avatar answered Apr 15 '26 01:04

Sergio


Try this regex:

^[^0-9]+    // get all non-numeric character and stop when it meets numeric character..
like image 41
invisal Avatar answered Apr 15 '26 02:04

invisal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!