Welcome to WebmasterWorld Guest from 126.96.36.199 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Pubcon Platinum Sponsor 2014
Regular expression help wanted How to get at bit not matched neiljones
I am still quite new to PHP and I simply cannot find out how to do this.
I have a situation where I have the following file name to manipulate in code.
where nnn could be a number from 1 into the thousands and where variablebit could be alphas and numerics even with a numeric on the end.
I need to get at the nnn.extension bit.
Now in perl this would be easy you would to a regexp to match the variablebit and the rest would be in $'
Now how do I achieve this in PHP?
I'm assuming you are going to use a function like preg_match [ php.net]? If you have a regex to match the variablebit, just add a second parenthesized subpattern to match the non-variablebit. Then use the
parameter to pull out the part you want. Make sense? DrDoc
$filename = "variablebitnnnn.ext"; $var = "variablebit"; $num_plus_ext = preg_replace("/^$var/","",$filename); neiljones
Thanks! That works perfectly. coopster
Neat way to do it DrDoc.