ReReplacer supports the use of powerful Regular Expressions to search and replace. This opens up endless possibilities and makes it possible and easy to make your own custom Plugin-Style Tags.
This means you can place a simple little text like {mytag}
in your content that (usually dynamically) gets replaced with something more complex.
Let's say you want to create a dynamic plugin-style tag to place images of animals quickly and easily. So {animal cat}
would place your cat.jpg
image, and {animal dog}
would place dog.jpg
, etc.
After switching on the "Regular Expressions" setting, the search field should contain:
\{animal (.*?)\}
And the replace field something like:
<img src="/images/animals/\1.jpg" alt="\1" />
Explanation
Let's explain this Regular Expressions search:
In regular expressions there are a lot of special characters that have special meanings. To search for the actual character, you need to 'escape' it with a backward slash (\
).
The {
and }
have special meanings in regular expressions, so to match the actual {
and }
you need to escape \{
and \}
.
The (.*?)
has a bit of magic going on. This regex statement is used very often. It pretty much means: grab all the text until you find the character after this statement, in our case '}
'.
The (
and )
make sure that the content matched by the statement is stored, so you can later use it in the replacement.
So then we come to the replacement. That is pretty much all standard html, except the \1
part. That refers to the first (and in our case, only) captured match in the search: (.*?)
. That contains the value 'cats' or 'dog' or whatever you placed inside the {animal}
tag in your article.
More on Regular Expressions
For help and documentation on regular expressions, ReReplacer comes with a Regular Expressions Cheat Sheet.
For more info on Regular Expressions: http://www.regular-expressions.info/reference.html
For testing them: http://gskinner.com/RegExr, http://regexpal.com, http://www.phpliveregex.com
More Plugin-Style Tags Examples
You can find more examples of creating and using custom plugin-style tags in the ReReplacer Examples Page.