0

I have the following text:

(Some text before...)
display_name = lo
name = lo
is_up = 1
index = 1
is_virtual = 0
is_point_to_point = 0
MTU = 65536
hardware_address = (null)
parent = (null)
ip_counter = 2
inet6 addr = /::1
inet addr = /127.0.0.1
---------------End_of_text---------------------
(Some text after...)

I'm trying to get this all part between "display_name = lo" and "---------------End_of_text---------------------", when "display_name = lo" and "End_of_text" are not include.

I tried to run the following:

String pattern = "^\\sdisplay_name = lo\\s+(.*)---------------End_of_text---------------------";

        Pattern r = Pattern.compile(pattern, Pattern.DOTALL);

        Matcher m = r.matcher(interfaceData);

        if (m.find()){
            System.out.println("Group 0 found value: " + m.group(0) );
            System.out.println("Group 1 found value: " + m.group(1) );
            System.out.println("Group 2 found value: " + m.group(2) );
        }
        else {System.out.println("NO MATCH");}

There is no match, what am I missing?

Atid
  • 1
  • 2
  • `---------------Start_vpn_sig---------------------` is not the same as `---------------End_of_text---------------------` There is also a `\s` before display_name https://regex101.com/r/7j42FW/1 – The fourth bird Apr 24 '20 at 12:06
  • The issue is that `.` does not match line breaks by default. Use `Pattern.DOTALL` or add `(?s)` at the start of the pattern – Wiktor Stribiżew Apr 24 '20 at 12:08

0 Answers0