Re: Regex Help with -> ?
| From: | sven | Date: | Fri, 27 Jun 2003 09:09:19 +0000 |
| Subject: | Re: Regex Help with -> ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-153075@lists.php.net to get a copy of this message | ||
looks like id3v2 ;-)
how about this:
$string = "<[TIT2]> ABC <[TPE1]> GHI <[TALB]> XYZ";
$pattern = "/<\[TIT2\]>([^<]*)/"; // matches anything exept '<';
till '<' or
end of string
preg_match($pattern, $string, $match);
var_export($match);
hint to your regex:
either use quantifier '*' (0-n times) OR '?' (0-1 times)
ciao SVEN
"Gerard Samuel" <gsam@trini0.org> schrieb im Newsbeitrag
news:3EFB48C9.5070903@trini0.org...
> I have a string something like ->
> <[TIT2]> ABC <[TPE1]> GHI <[TALB]> XYZ
> Im applying a regex as such ->
> // Title/Songname/Content
> preg_match('/<\[TIT2\]>(.*?)(<\[)?/', $foo, $match);
> $title = trim( $match[1] );
>
> The above regex doesn't work. At the end of the pattern Im using (<\[)?
> The pattern may or may not end with <[
> For example searching for -> <[TALB]> XYZ
> The string, is *NOT* expected to hold a certain order as how it is
> retrieved.
> How does one go about to fix up this regex?
>
> Thanks
>