3

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

3 Answers 3

4

Try this regex:

^.*?(?=\d)    //start lookup from linestart, get all symbols before first number occurance
Sign up to request clarification or add additional context in comments.

4 Comments

waiting 2 mint more .. as system request ;)
Noted that this will not work if there is no number. For example: "Google Chrome" <-- not match.
@invisal depends on task and requirements. Your solution works as well but matches whitespace strings :)
@Sergio, don't get me wrong. I am not complaining about your solution. I just want to give some extra information to OP. From OP sample data, he probably want to get only browser name and there is chance that there is some browser name without version number.
4

Try this regex:

^[^0-9]+    // get all non-numeric character and stop when it meets numeric character..

Comments

2

Here usng preg_match_all

$txt =<<<EOT
Avant Browser 2013 Build 110
Firefox 23.0 Beta 10
Google Chrome 29.0.1547.41 Beta
EOT;

preg_match_all('/^([^0-9]*)/m',$txt,$match);

var_dump($match);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.