Title: Gallery From Regex Matches
Author: doddo
Published: <strong>January 8, 2018</strong>
Last modified: May 30, 2019

---

Search plugins

![](https://ps.w.org/gallery-from-regex-matches/assets/banner-772x250.jpg?rev=1802650)

This plugin **hasn’t been tested with the latest 3 major releases of WordPress**.
It may no longer be maintained or supported and may have compatibility issues when
used with more recent versions of WordPress.

![](https://ps.w.org/gallery-from-regex-matches/assets/icon-256x256.png?rev=1800844)

# Gallery From Regex Matches

 By [doddo](https://profiles.wordpress.org/doddo/)

[Download](https://downloads.wordpress.org/plugin/gallery-from-regex-matches.0.6.3.zip)

 * [Details](https://wordpress.org/plugins/gallery-from-regex-matches/#description)
 * [Reviews](https://wordpress.org/plugins/gallery-from-regex-matches/#reviews)
 *  [Installation](https://wordpress.org/plugins/gallery-from-regex-matches/#installation)
 * [Development](https://wordpress.org/plugins/gallery-from-regex-matches/#developers)

 [Support](https://wordpress.org/support/plugin/gallery-from-regex-matches/)

## Description

A plugin which adds a shortcode: `[gallery_from_regex_matches]` in which a regex
attribute should be specified. It will then look for matches in the descriptions
and titles of all published images in your library, and create a gallery from the
matches it finds.

 * Use for example like this `[gallery_from_regex_matches regex="lillill" exclude_ids
   ="764"]`, and it will generate a gallery of all your pictures of “Lillill”, except
   the one which has ID 764.
 * Sometimes it might be advicable to limit the amount of matches. that can be achieved
   by adding `limit` to the shortcode. `[gallery_from_regex_matches regex="lillill"
   exclude_ids="764" limit="10"]`.
 * Sometimes you want to make a gallery of “cats” but not “catsup”, but you don’t
   want to add [word boundary](https://dev.mysql.com/doc/refman/5.7/en/regexp.html)`[[:
   >:]]`, in this case you can `exclude_regex=catsup`. Then it could look something
   along the line of `[gallery_from_regex_matches regex="cats" exclude_regex="catsup"]`.
 * The same params (except for `ids`) as for the `[media]` shortcode can be used(
   as this plugin calls that shortcodes callback function (`gallery_shortcode()`)
   to generate the gallery), so if you want to specify a particular type (style)
   of gallery from for example your cat pictures , this might do the trick: `[gallery_from_regex_matches
   regex="(cat|kitten)" type="square"]`.
 * The regular expressions follows the [MySQL Regexp syntax](https://dev.mysql.com/doc/refman/5.7/en/regexp.html)
 * Some characters will per default not work inside of the shortcode, see the “Caveats”
   section.
 * There are no bells and whistles for this plugin but it could potentionally be
   added in the futre.

### Caveats

Since the regex used by the plugin is specified as an attribute value inside of 
a shortcode, and the [Shortcode Api](https://codex.wordpress.org/Shortcode_API) 
disallows the use of certain characters which could be a part of a valid, useful
regex, there are some things to consider.

> Attribute values must never contain the following characters:
>  * Square braces:[]*
> Quotes: ” ‘
> [ … ]
>  The recommended method of escaping special characters in shortcode attributes
> is HTML encoding. Most importantly, any user input appearing in a shortcode attribute
> must be escaped or stripped of special characters.

 * if in the regex you need to macth a character set `[a-z]`, then (following the
   shortcode Api documentation guidline), they need to be encoded. There are two
   encodings which the plugin accepts: “html” and “base64”
 * Currently there is no way to encode these things with help of the plugin, although
   it is planned for a future release, so the regexes must be encoded manually for
   now’
    For example, for regex `w[0u][0u]ti` can be expressed either:

With HTML encoding:
 `[gallery_from_regex_matches regex="w&#091;0u&#093;&#091;0u&#
093;ti" encoding="html"]`

With Base64 encoding:
 `[gallery_from_regex_matches regex="d1swdV1bMHVddGk=" encoding
="base64"]`

To encode a string to base64, it can be done from the terminal like this:
 `% echo-
n "catsup" | base64 Y2F0c3Vw % echo -n Y2F0c3Vw | base64 --decode catsup%

## Installation

 1. unpack the zip into the `/wp-content/plugins` dir
 2. Activate the plugin through the ‘Plugins’ menu

## Reviews

![](https://secure.gravatar.com/avatar/f3c8ccc572a56d076e602f8b81f5816d8973ebe20e9cf0135cb2e3595d72235f?
s=60&d=retro&r=g)

### 󠀁[Excellent plugin](https://wordpress.org/support/topic/excellent-plugin-3664/)󠁿

 [xnaveira](https://profiles.wordpress.org/xnaveira/) February 5, 2018

We needed to group the pictures in our gallery in a way that wasn’t obvious but 
this plugin flexibility got the job done! Totally recommended.

 [ Read all 1 review ](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/)

## Contributors & Developers

“Gallery From Regex Matches” is open source software. The following people have 
contributed to this plugin.

Contributors

 *   [ doddo ](https://profiles.wordpress.org/doddo/)

“Gallery From Regex Matches” has been translated into 1 locale. Thank you to [the translators](https://translate.wordpress.org/projects/wp-plugins/gallery-from-regex-matches/contributors)
for their contributions.

[Translate “Gallery From Regex Matches” into your language.](https://translate.wordpress.org/projects/wp-plugins/gallery-from-regex-matches)

### Interested in development?

[Browse the code](https://plugins.trac.wordpress.org/browser/gallery-from-regex-matches/),
check out the [SVN repository](https://plugins.svn.wordpress.org/gallery-from-regex-matches/),
or subscribe to the [development log](https://plugins.trac.wordpress.org/log/gallery-from-regex-matches/)
by [RSS](https://plugins.trac.wordpress.org/log/gallery-from-regex-matches/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

#### 0.6.3

 * Fixed a bug in which attachments with no parent were never selected.

#### 0.6.2

 * Fixed a bug with mysql query and empty regexp

#### 0.6.1

 * Added `exclude_regex` shortcode parameter.

#### 0.6.0

 * Move the regex matching into the database and use MySQL regex syntax instead 
   of calling all posts and applying the regex filters on them. This to increase
   performance and to work better on big galleries.
 * Syntax for regex attr then is also slightly changed: no need to use delimiter‘/’:“`/(
   cat|kitten)/`” is now written “`(cat|kitten)`“, but either way will work for 
   backwards-compatiblity reasons.
 * Number of matches can now be limited with the `limit` which defaults to 10000,
   but can be set to a higher value if need be.

#### 0.5.1

 * Add possibility of decoding encoded regexes, so that special characters which
   would collide with the Shortcode Api can still be used in them.

#### 0.5

 * Search also title field
 * use preg_grep on array of target search fields instead of concatinating it to
   a string as that can lead to unforseen matches.

#### 0.1

First pre-prod version with potential bugs in it.

## Meta

 *  Version **0.6.3**
 *  Last updated **7 years ago**
 *  Active installations **Fewer than 10**
 *  WordPress version ** 4.9.1 or higher **
 *  Tested up to **5.2.24**
 *  PHP version ** 7.0 or higher **
 *  Languages
 * [English (US)](https://wordpress.org/plugins/gallery-from-regex-matches/) and
   [Swedish](https://sv.wordpress.org/plugins/gallery-from-regex-matches/).
 *  [Translate into your language](https://translate.wordpress.org/projects/wp-plugins/gallery-from-regex-matches)
 * Tag
 * [gallery](https://wordpress.org/plugins/tags/gallery/)
 *  [Advanced View](https://wordpress.org/plugins/gallery-from-regex-matches/advanced/)

## Ratings

 5 out of 5 stars.

 *  [  1 5-star review     ](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/?filter=5)
 *  [  0 4-star reviews     ](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/?filter=3)
 *  [  0 2-star reviews     ](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/?filter=2)
 *  [  0 1-star reviews     ](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/gallery-from-regex-matches/reviews/)

## Contributors

 *   [ doddo ](https://profiles.wordpress.org/doddo/)

## Support

Got something to say? Need help?

 [View support forum](https://wordpress.org/support/plugin/gallery-from-regex-matches/)