문제

I am trying to match certain string it goes like this:

apn xxxxx
      blah blah blah
      blah -blah blah blah -blah -blah blah-blah-blah
      blah-blah
      blah blah blah-1 blah-blah BLAH
      blah blah BLAH-2 blah-blahBLAH
      blah blah BLAH-3 blah-blahBLAH
      blah blah BLAH-4 blah-blahBLAH
      blah-blah blah-blah blah  1 blah-blah blah
      blah blah 2000
      blah blah 600
      ipv6 primary fc00:a:a::300
      ipv6 secondary fc00:a:a::400
      blah blah-blah blah-blah-blah-blah-blah blah
      blah blah-blahblah-blah-blah-blah-blah blah
      blah blah-blah-blah BLAH_BLAH_BLAH_BLAH
      blah-blah blah BLAH
      blah-blah blah 2000
    exit

I am trying to match the text fc00:a:a::300 with ipv6 primary as the anchor while using the xxxx as a key. I am trying to use a working regex pattern that matches all the possible blahs that would contain any character. Any suggestions?

I've tried using \s[\w+\-]\s+ipv6\s+dns primary\s+ but am not able to match the text.

도움이 되었습니까?

해결책

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.

demo


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.

demo

다른 팁

apn xxxx[\s\S]*?ipv6 primary (.*)

should do .

demo here: http://regex101.com/r/tB5tJ0

Try this,

  1. set your lengthy string in a variable as set a {.... .... ....}

  2. Apply this command regexp {.*ipv6\sprimary\s+(\S+)} $a t t1

The output for t1 will be as "fc00:a:a::300".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top