Custom Regex Placeholders
This documentation site is deprecated. Please visit the control panel at https://monitorss.xyz for all up-to-date functionality
Regular Expressions (regex) is used to find, modify, and replace content. Suppose you want to remove/modify specific text. Or you want to remove some copyright text or whatever. Regex can do this.
All regex is applied after the text is internally sanitized/filtered, and before it is truncated (if necessary). The content you see through a test message (with [Filters Passed]: Yes) is the most accurate depiction of what your regex will be working on (content might be truncated in the test however).
Recommendation
Before applying any regexOps, you should first test your expressions and replacements at https://regex101.com/. Brute-testing regex can be quite frustrating without trying it first.
Usage/Syntax
Regex cannot be specified via Discord commands - you will have to modify your feed JSON to do so. Each regexOp object has a name
key, where you will then refer to it in Discord as {placeholder:myName} where myName would be the value of the key. The placeholder can be any valid placeholder found in the command output of test
for a feed. Ex: {title:SpecialName}.
The object "regexOps" is added to a feed object, and the outline is this:
Required
"placeholder"
- Replaceplaceholder
with any placeholder such as description, title, etc..Required
"name"
- Reference to what the custom placeholder will be named. If there is no name, the regexOp in question will be ignored. For example in the snippet above, it would be referred to as {placeholder:whatever}.Required
"search"
- The value should be an object of the following keys:Required
"regex"
- Your regex expression.Optional
"match"
- Match number (not string) from your regex expression. Defaults to0
. Note that the first match is 0 and not 1.Optional
"group"
- Group number (not string) of the selected match from your regex expression. Defaults to0
(the full match).Optional
"flags"
- Javascript regex flags. Defaults to"gi"
Optional
"replacement"
- A replacement string value that will replace all instances of the search in the original string.Optional
"replacementDirect"
- Directly input your own regex into the second argument of.search
function for a replacement. This will override thereplacement
key.
If the replacement
key is undefined (meaning the key does not exist), then your custom placeholder will return your search results.
If the replacement
is defined, then your custom placeholder will return the original placeholder content with all instances of the search results replaced by your replacement
string.
Chained Regex
More than one regexOp can be added for a placeholder by simply adding another regexOp object:
The order and name matters! Named regexOps are executed from top to bottom.
Disabling
You can temporarily disable all regexOps, add the "disabled"
key:
To disable multiple placeholders instead of disabling all regexOps, replace "disabled"
boolean value with an array of whatever placeholders you want disabled: "disabled": ["description", "title"]
or "disabled": ["title"]
You can also disable a specific regexOp by adding "disabled": true
as well.
Errors
Regex errors will by default be shown for articles that the regex can't find a match for. To disable visible errors, change config.feeds.showRegexErrs
to false.
Last updated