Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
g

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}\\/\\d+"; final String string = "LG \n\n\n" + "MegaFon Looking Glass - show bgp 10.249.0.0/16\n\n\n\n\n" + "Router: MSK-VRR-1 Moscow \n" + "Command: show route protocol bgp 10.249.0.0/16 table bgp.l3vpn.0 det | no-more \n\n\n\n" + "bgp.l3vpn.0: 228890 destinations, 628337 routes (227275 active, 0 holddown, 5064 hidden)\n" + "Restart Complete\n" + "83.149.11.41:100:10.249.50.224/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.41:100:10.249.50.232/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.41:100:10.249.50.248/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.41:100:10.249.150.224/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.41:100:10.249.150.232/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.41:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68a78c\n" + " Next-hop reference count: 267\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.41\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:57:04 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.42:100:10.249.50.224/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.42:100:10.249.50.232/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.42:100:10.249.50.248/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.42:100:10.249.150.224/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.42:100:10.249.150.232/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.42:100\n" + " Next hop type: Indirect\n" + " Address: 0xa68ab1c\n" + " Next-hop reference count: 258\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.42\n" + " Push 17\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 2w2d 16:56:39 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 31133:100 target:25159:25159 target:64690:100 target:64999:15 \n" + " Accepted\n" + " VPN Label: 17\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.65:1065:10.249.28.168/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.65:1065\n" + " Next hop type: Indirect\n" + " Address: 0xa68bcec\n" + " Next-hop reference count: 3\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.65\n" + " Push 27775\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 28w0d 0:58:33 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 25159:64666 31133:100 target:64999:1065 \n" + " Accepted\n" + " VPN Label: 27775\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.65:1065\n" + " Next hop type: Indirect\n" + " Address: 0xa68bcec\n" + " Next-hop reference count: 3\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.65\n" + " Push 27775\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 28w0d 0:58:44 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 25159:64666 31133:100 target:64999:1065 \n" + " Accepted\n" + " VPN Label: 27775\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.65:1065\n" + " Next hop type: Indirect\n" + " Address: 0xa68bcec\n" + " Next-hop reference count: 3\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.65\n" + " Push 27775\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 12w0d 2:17:42 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 25159:64666 31133:100 target:64999:1065 \n" + " Accepted\n" + " VPN Label: 27775\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.66:1065:10.249.28.168/29 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.66:1065\n" + " Next hop type: Indirect\n" + " Address: 0x9ed8860\n" + " Next-hop reference count: 3\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.66\n" + " Push 27764\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 28w0d 0:58:34 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 ?\n" + " Communities: 25159:64666 31133:100 target:64999:1065 \n" + " Accepted\n" + " VPN Label: 27764\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.66:1065\n" + " Next hop type: Indirect\n" + " Address: 0x9ed8860\n" + " Next-hop reference count: 3\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.66\n" + " Push 27764\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 28w0d 0:58:49 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 ?\n" + " Communities: 25159:64666 31133:100 target:64999:1065 \n" + " Accepted\n" + " VPN Label: 27764\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.66:1065\n" + " Next hop type: Indirect\n" + " Address: 0x9ed8860\n" + " Next-hop reference count: 3\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.66\n" + " Push 27764\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 12w0d 2:17:42 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 ?\n" + " Communities: 25159:64666 31133:100 target:64999:1065 \n" + " Accepted\n" + " VPN Label: 27764\n" + " Localpref: 200\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.101:1039:10.249.64.0/18 (3 entries, 1 announced)\n" + " *BGP Preference: 170/-101\n" + " Route Distinguisher: 83.149.11.101:1039\n" + " Next hop type: Indirect\n" + " Address: 0x10fb4d20\n" + " Next-hop reference count: 12\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.101\n" + " Push 63\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 8w5d 3:07:17 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 64626 ?\n" + " Communities: 31133:100 target:64999:1039 \n" + " Accepted\n" + " VPN Label: 63\n" + " Localpref: 100\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-101\n" + " Route Distinguisher: 83.149.11.101:1039\n" + " Next hop type: Indirect\n" + " Address: 0x10fb4d20\n" + " Next-hop reference count: 12\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.101\n" + " Push 63\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Active preferred\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 8w5d 3:07:17 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " AS path: 25159 64626 ?\n" + " Communities: 31133:100 target:64999:1039 \n" + " Accepted\n" + " VPN Label: 63\n" + " Localpref: 100\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-101\n" + " Route Distinguisher: 83.149.11.101:1039\n" + " Next hop type: Indirect\n" + " Address: 0x10fb4d20\n" + " Next-hop reference count: 12\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.101\n" + " Push 63\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Not Best in its group - Interior > Exterior > Exterior via Interior\n" + " Local AS: 31133 Peer AS: 31133\n" + " Age: 8w5d 3:07:17 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_31133.10.222.253.245+???\n" + " AS path: 25159 64626 ?\n" + " Communities: 31133:100 target:64999:1039 \n" + " Accepted\n" + " VPN Label: 63\n" + " Localpref: 100\n" + " Router ID: 10.222.253.245\n\n" + "83.149.11.120:196:10.249.109.0/24 (3 entries, 1 announced)\n" + " *BGP Preference: 169/-201\n" + " Route Distinguisher: 83.149.11.120:196\n" + " Next hop type: Indirect\n" + " Address: 0x11399fd4\n" + " Next-hop reference count: 6\n" + " Source: 83.149.11.251\n" + " Protocol next hop: 83.149.11.120\n" + " Push 33\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Active Ext ProtectionPath ProtectionCand>\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 11w2d 1:53:58 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.251+???\n" + " Announcement bits (1): 0-BGP_RT_Background \n" + " AS path: 25159 I\n" + " Communities: 31133:100 target:64999:196 \n" + " Accepted\n" + " VPN Label: 33\n" + " Localpref: 200\n" + " Router ID: 83.149.11.251\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.120:196\n" + " Next hop type: Indirect\n" + " Address: 0x11399fd4\n" + " Next-hop reference count: 6\n" + " Source: 83.149.11.252\n" + " Protocol next hop: 83.149.11.120\n" + " Push 33\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <Ext ProtectionPath ProtectionCand>\n" + " Inactive reason: Route Preference\n" + " Local AS: 31133 Peer AS: 25159\n" + " Age: 11w2d 1:53:58 Metric2: 1 \n" + " Validation State: unverified \n" + " Task: BGP_25159.83.149.11.252+???\n" + " AS path: 25159 I\n" + " Communities: 31133:100 target:64999:196 \n" + " Accepted\n" + " VPN Label: 33\n" + " Localpref: 200\n" + " Router ID: 83.149.11.252\n" + " BGP Preference: 170/-201\n" + " Route Distinguisher: 83.149.11.120:196\n" + " Next hop type: Indirect\n" + " Address: 0x11399fd4\n" + " Next-hop reference count: 6\n" + " Source: 10.222.253.245\n" + " Protocol next hop: 83.149.11.120\n" + " Push 33\n" + " Indirect next hop: 0x2 no-forward INH Session ID: 0x0\n" + " State: <NotBest Int Ext ProtectionPath ProtectionCand>\n\n\n\n\n\n\n" + "Disclaimer: All commands will be logged for possible later analysis and statistics. If you don't like this policy, please disconnect now! \n\n\n\n" + " Please email questions or comments to noc@megafon.ru. \n\n"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html