Page 1 of 1

Regex-get integer between tags

Posted: Mon Jan 11, 2010 3:08 am
by rupam_jaiswal
Hi,
Please excuse if similar issue has been posted earlier.
My data is like

I am going [ABCDEF]123[/ABCDEF] to movie.
I want a regex to get the value between [ABCDEF] and [/ABCDEF] only if its integer.
eg if its [ABCDEF]junk characters[/ABCDEF] then I dont want...but if its [ABCDEF]123[/ABCDEF]
then I require 123

Regards

Re: Regex-get integer between tags

Posted: Mon Jan 11, 2010 3:45 am
by papa

Code: Select all

 
<?php
$subject = "[ABCDEF]123[/ABCDEF]";
$pattern = '#\[ABCDEF\](\d+)\[/ABCDEF\]#';
preg_match($pattern, $subject, $matches);
print_r($matches);
?>