如何使用正则表达式在下划线之间选择数字?

I want to get only the value in bold, but I'm not getting.

349141_194419414_4828414_n.jpg

or

https:// hphotos-ash3.net/t1.0-9/1146_54482593153_1214114_n.jpg

Thank you already

You can use preg_match with a capture group to get the result:

<?php
    $searchText = "349141_194419414_4828414_n.jpg";

    $result = preg_match("/_(\\d+)_/u", $searchText, $matches);
    print_r($matches[1]);
?>

output:

194419414

(i'm not sure whether this one is good method or not but you can get whatever value you want to by this)

$r="349141_194419414_4828414_n";
print_r(explode('_',$r));

output:

Array ( [0] => 349141 [1] => 194419414 [2] => 4828414 [3] => n )

$rr=explode('_',$r);
echo $rr[1];

output

194419414

Here's a regular expression answer.

$filename = '349141_194419414_4828414_n.jpg';

preg_match_all('/[0-9]+/', $filename, $matches);

echo $matches[0][1]; //194419414

Try something like this:

.+/\d+_(\d+)_\d+_n.jpg