Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 15133

Scripting • Re: Using regex in Mikrotik and creating search functions with return values

$
0
0
do you have a simplified version? wherein we can only get the exact word ? like a reference number on text sms ?
For your case, you can still use the findPosix function, but you only need the first element of the returned array, which contains the found substring
Usage example:
Code:
/system script run ScriptFindPosix;# This command can be run when loading the router once to initialize the global variable FindRegex, which will store the search function:global findPosix;# global variable declaration#-----------replace the value of YOURString and regex variables-----------:local YOURString "INSERT YOUR TEXT";:local regex "INSERT YOUR REGULAR EXPRESSION HERE";:local startPosition 0;:local ArrRezult [$findPosix $YOURString $regex $startPosition ];# return value: ArrRezult  is array {FoundSubString ; PositionStart ; PositionEnd }:local FoundSubString [:pick $ArrRezult 0];:put $FoundSubString  # the $FoundSubString contains the found string

Statistics: Posted by vadimsachkov — Tue Feb 27, 2024 9:30 am



Viewing all articles
Browse latest Browse all 15133

Trending Articles