G
G
Grigory Shchetintsev2017-10-28 16:12:14
Mikrotik
Grigory Shchetintsev, 2017-10-28 16:12:14

How to build a regular expression for syntax processing?

Because I blog (although this is more of a note from life) I try to arrange everything beautifully.
Before that, I used a simple tag to insert commands from RouterOS
. I sat down and thought about writing a simple plugin for Wordpress for syntax highlighting, like in the RouterOS terminal: It's a
59f47f9acae2b709792661.png
start, but I ran into a problem. Namely, with regular expressions .. Yes, yes, those very ones, with the help of which you need to catch characters, certain commands and a bunch of everything else.
I ask for all possible help in writing a plugin, or rather in writing a regular expression.
Code on github:
Code on GitHub
At the moment I'm using the
preg_replace
Split code feature to search for different sets, here's the search for Incoming Menus:
$commandTerm and $inputTerm are a set of commands that can be entered separated by spaces in a textarea in a plugin.
Those. all the words that we need to find we enter into various inputs (textarea)

/([\:])('.$commandTerm.')|[\/]('.$inputTerm.')[\s]|\b('.$inputTerm.')\b/ui

We have several colors for different types of actions
1. Menu entry and transitions rgb(0,155,155)
2. Commands rgb(155,0,155)
3. Parameters rgb(0,155,0)
4. Symbols rgb(155,155,0)
While in the plugin this is looks like this:
59f4801c6fc34272792488.png
If you can do everything as it should. This code will be useful to many who are engaged in Mikrotiks and share information on them with others.
Yes, and aesthetically.
Here is the original from the RouterOS terminal
59f481c5dc67b470552000.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question