How to use Regex to match PHP time() or microtime() in a string? -


i have regex command matches php time in string:

preg_match( '/([a-z]+)_([0-9]{9,})\.jpg/i', $aname, $lmatches ); 

how can modify match microtime() in same match?

examples:

foobar_1453887550.jpg (match)

foobar_1453887620.8717.jpg (match)

foobar_123.jpg (don't match)

foobar_adsf123123.jpg (don't match)

add optional group using ?:

preg_match( '/([a-z]+)_([0-9]{9,})(\.[0-9]{4,})?\.jpg/i', $aname, $lmatches ); 

here (\.[0-9]{4,})? optional group can present or not in string.

considering @trincot remark can change optional group (\.[0-9]+)? if ending zeroes not present in milliseconds.

preg_match( '/([a-z]+)_([0-9]{9,})(\.[0-9]+)?\.jpg/i', $aname, $lmatches );  

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -