Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

using regex to extract data

or any other method ...

1:22 am on Sep 11, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2003
votes: 0


How can I extract the number 19 from the string product_27001_th19.jpg . The solution needs to be dynamic, as the function should return 19 for all the following:


I am perl programmer and not sure how to do this in php.



1:40 am on Sept 11, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2003
votes: 0

1) Do you want it in PHP or Perl? This is a Perl forum.
2) What do you want to do with 19 later? If you just want to extract 19 whats the point? It'a always 19...

Am I missing something?

8:13 am on Sept 11, 2003 (gmt 0)

New User

10+ Year Member

joined:Aug 14, 2003
votes: 0

If '19' appers only before dot that separates filename from extention than you may try this code in perl:

my ($number) = $filename =~ m/(\d+)\.[^.]+$/;

Here $filename must contain your filename, and $number receives '19' or any other number that was in filename.

update: oops, you wish to do that in php....