Log in

View Full Version : Simple regex match **after** a period?



JAB Creations
05-24-2008, 04:10 PM
I'm trying to figure out how to make a regex to match after a period. In example the string 'af24cca.z' would match as 'z', or '24t24.4f' would match as '4f'.


$cookie = 'audio.0_backgroundimages._browserpatch.1';

$my_pattern = '/^(\.){1}/';

list($audio, $backgroundimages, $browserpatch) = split($my_pattern, $cookie);
echo $audio;

In the script above the desired match in this instance would be '0'.

Master_script_maker
05-25-2008, 11:28 AM
$cookie = 'audio.0_backgroundimages._browserpatch.1';

$my_pattern = '/^(\.){1}/';

list($audio, $backgroundimages, $browserpatch) = split($my_pattern, $cookie);
echo $audio;
^ means at the beginning of the string meaning you want to split the string at the first character if it is a period.
try

$my_pattern = '/(\.){1}/';

JAB Creations
05-27-2008, 03:45 PM
Hmm, nothing is working; any suggestions for a more indepth regex cheat sheet?

Master_script_maker
05-27-2008, 05:40 PM
after checking php.net (http://us.php.net/manual/en/function.split.php), i think the regex should be [.]

JAB Creations
05-28-2008, 02:14 PM
Ah! I see! I was using regex slashes / / though they are unnecessary and prevent the script from operating correctly. I figured it was regex, what's the catch?

boogyman
05-28-2008, 02:28 PM
after checking php.net (http://us.php.net/manual/en/function.split.php), i think the regex should be [.]
that would match any character, because the dot is a wildcard in terms of regular expressions, I am pretty sure you would need to do
[\.]


Ah! I see! I was using regex slashes / / though they are unnecessary and prevent the script from operating correctly. I figured it was regex, what's the catch?

can you re-phrase that?

/expression/ is what lets the language know that what you are about to declare is a regular expression.