First of all you must split on three parts because the IP is not at the start and not at the end, like other lists…
Space replaced with “·”
:do·{·add·address=|2.84.0.0/14|·list=GR·}·on-error={}left delimiter:
address=
right delimiter:
·list=
including space
Example for CLI, I use global just for the test, on script can/must be used local.
# test string
:global teststr ":do { add address=2.84.0.0/14 list=GR } on-error={}\r\n:do { add address=5.54.0.0/15 list=GR } on-error={}"
# remove head and tail, used + 8 because is the character lenght of "address="
# instead of a fixed value can be set also, for example, with [:len $rightstrdelimiter] on script
# notice the needed space before list
:global testip [:pick $teststr ([:find $teststr "address=" -1] + 8) [:find $teststr " list=" -1]]
# now I chech against regexp if is valid IP-prefix
:if ($testip~"((25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])\\.){3}(25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])\\/(3[0-2]|[0-2]\?[0-9])") do={ \
:put "$testip is a IP-prefix"
} else={:put "$testip is NOT a IP-prefix"}
Doing again adding last “right” position value (on example 29), give next IP, without split the file on lines and without modify everytime the data value.
:global testip [:pick $teststr ([:find $teststr "address=" 29] + 8) [:find $teststr " list=" 29]]
:if ($testip~"((25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])\\.){3}(25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])\\/(3[0-2]|[0-2]\?[0-9])") do={ \
:put "$testip is a IP-prefix"
} else={:put "$testip is NOT a IP-prefix"}