Page 1 of 1

get a substring

Posted: Thu Aug 28, 2003 10:24 am
by yaron
hello all,
I have a string which has a number in it.
What I need is the substring that comes after the number.

for example:
hello-99goodbye.txt
I need to output => goodbye.txt
I'm guessing it's perl but I'm quite new at this.
Thank you all.

Posted: Thu Aug 28, 2003 10:44 am
by volka

Code: Select all

<?php
$text = 'hello-99goodbye.txt';
if (preg_match('!\d+(.*)$!', $text, $match))
	echo $match[1];
else
	echo 'no match';
?>

Posted: Thu Aug 28, 2003 10:47 am
by delorian
Yes, perl comes in handy sometimes :D

Code: Select all

$array = preg_split("|[\d]+|",$text);
// the last element in that array should be the goodbye.txt
I guess that will work.