I have a string like
[gallery GALLERYNAME] [gallery GALLERYNAME]
the GALLERYNAME indicates a name of a gallery
What would a regular expression looks like to match this string?
\[gallery ([^\]]+)\]
<?php
preg_match( "@\[gallery ([^\]]+)\]@", "foo [gallery GALLERYNAME] bar", $match );
var_dump( $match );
// $match[ 1 ] should contain "GALLERYNAME"
?>
As an alternate:
<?php
preg_match_all( "@\[gallery ([^\]]+)\]@m", "
foo [gallery GALLERYNAME1] bar
foo [gallery GALLERYNAME2] bar
foo [gallery GALLERYNAME3] bar
", $match );
var_dump( $match );
// $match[ 1 ] should contain an array containing the desired matches
?>
要匹配“GALLERYNAME”:
^\[gallery\s([A-Z]+)\]$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.