windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

Best way to extract the data from the string

Asked By: Anonymous

I want to parse the mobile number from the string. The string may have a landline and extension code and a mobile number. The mobile number always starts with "Mobile:"

For example:

Phone: xxx-xxx-xxxx ext. 215 => return Empty

Phone: xxx-xxx-xxxx Mobile: 9xx-xxx-x000 => return 9xx-xxx-x000

Mobile: 9xx-xxx-x000 Phone: xxx-xxx-xxxx => return 9xx-xxx-x000

Phone: xxx-xxx-xxxx Mobile: 9xx-xxx-x000 ext. 215 => return 9xx-xxx-x000

Mobile: 9xx-xxx-x000 Phone: xxx-xxx-xxxx ext. 215 => return 9xx-xxx-x000

Phone: xxx-xxx-xxxx ext. 215 Mobile: 9xx-xxx-x000 => return 9xx-xxx-x000

I have tried following code to extract the mobile number but it’s not working correctly –

$stringList = [
            "a" => "Phone: xxx-xxx-xxxx ext. 215",
            "b" => "Phone: xxx-xxx-xxxx Mobile: 9xx-xxx-x000",
            "c" => "Mobile: 9xx-xxx-x000 Phone: xxx-xxx-xxxx",
            "d" => "Phone: xxx-xxx-xxxx Mobile: 9xx-xxx-x000 ext. 215",
            "e" => "Mobile: 9xx-xxx-x000 Phone: xxx-xxx-xxxx ext. 215",
            "f" => "Phone: xxx-xxx-xxxx ext. 215 Mobile: 9xx-xxx-x000"

        $stringOutput = [];
        foreach($stringList as $k => $s) {
            if(strpos($s, "Mobile:") !== false) {
                $parseString = substr($s, strpos($s, "Mobile:"));
                $parseString = explode("Phone:", $parseString)[0];
                $parseString = explode("ext.", $parseString)[0];
                $stringOutput[$k] = trim($parseString);

    [b] => Mobile: 9xx-xxx-x000
    [c] => Mobile: 9xx-xxx-x000
    [d] => Mobile: 9xx-xxx-x000
    [e] => Mobile: 9xx-xxx-x000
    [f] => Mobile: 9xx-xxx-x000

Is there any efficient way to achieve this task, are we able to parse this using regex or any other method?


Answered By: Anonymous

You could use a pattern with a capture group and a backreference to match the delimiters in the number.

bMobile:s*(d{3}([ -]?)d{3}2d{4})b
  • bMobile:s* Match the word Mobile: and optional whitespace chars
  • ( Capture group 1
    • d{3} Match 3 digits
    • ([ -]?) Capture group 2 match a delimiter being an optional or -
    • d{3} Match 3 digits
    • 2 Backreference to match the same as the captured delimiter in group 2
    • d{4} Match 4 digits
  • ) Close group 1
  • b A word boundary to prevent an empty match

Regex demo

$s = "Mobile: 911-111-1000 Phone: 111-111-1111";
$pattern = '/bMobile:s*(d{3}([ -]?)d{3}2d{4})b/';
if (preg_match($pattern, $s, $match)) {
    echo $match[1];



Or using K without the outer capture group:

bMobile:s*Kd{3}([ -]?)d{3}1d{4}b

Regex demo

$s = "Mobile: 9111111000 Phone: 111-111-1111";
$pattern = '/bMobile:s*Kd{3}([ -]?)d{3}1d{4}b/';
if (preg_match($pattern, $s, $match)) {
    echo $match[0];



techinplanet staff

Porno Gratuit Porno Français Adulte XXX Brazzers Porn College Girls Film érotique Hard Porn Inceste Famille Porno Japonais Asiatique Jeunes Filles Porno Latin Brown Femmes Porn Mobile Porn Russe Porn Stars Porno Arabe Turc Porno caché Porno de qualité HD Porno Gratuit Porno Mature de Milf Porno Noir Regarder Porn Relations Lesbiennes Secrétaire de Bureau Porn Sexe en Groupe Sexe Gay Sexe Oral Vidéo Amateur Vidéo Anal

Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno