You could try using something like this:
regexp -lineanchor -- {apn xxxxx.*?ipv6 primary\s*?([^\n]+)$} $text - match
You should get fc00:a:a::300
in the variable $match
.
apn xxxxx
will match exactly that.
.*?
will match any characters up to ipv6 primary
.
\s*?
will match any spaces
([^\n]+)
will match non-newlines until... $
(the end of line).
-lineanchor
makes $
match all end of lines.
If you don't want to match one that is outside of the apn xxxxx ... exit
, then you could use something like this:
regexp -lineanchor -- {apn xxxxx(?:(?!exit).)*?ipv6 primary\s*?([^\n]+)$} $text - match
(?:(?!exit).)*?
will match any character except exit
.