CodeTheft
CodeTheft

Reputation: 101

How to extract whole line text using regex?

i have a following piece of text i need a regular expression which give me the complete text of that line which starts from dhcp pool For e.g. first line starts from dhcp pool so i need complete text of it.Can anyone tell me how to achieve this ,it would be very helpful to me.

dhcp pool IT-test
IP address is 12.0.0.0,Network mask is 255.0.0.0
DHCP client node type : 0
Lease  day:1, hour: 0, minute :0
dhcp pool QA-Test
IP address is 192.168.100.0,Network mask is 255.255.255.0
DHCP client node type : 0
Lease  day:1, hour: 0, minute :0
dhcp pool firmware-test
IP address is 11.0.0.0,Network mask is 255.0.0.0
DHCP client node type : 0
Lease  day:1, hour: 0, minute :0

2nd piece of code:

 string pattern = "/^dhcp pool.*/g";
            Console.WriteLine(pattern);
            MatchCollection matches = Regex.Matches(_str, pattern);

            foreach(Match match in matches)
            {
                Console.WriteLine("+++++++++++++dhcp pool is ++++++++++++++" + match.Groups[1].Value);
                DHCPoolName = match.Groups[1].Value;
            }

XAML code:

<ComboBox
            Grid.Column="1"
            Grid.Row="1"
            Margin="0,4"
            ItemsSource="{Binding DHCPoolName}">              
        </ComboBox>

Upvotes: 1

Views: 1317

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Simply you could use the below regex

^dhcp pool.*

The above regex would match all the lines which starts with dhcp pool . ^ asserts that we are at the start. .* matches any character except line breaks zero or more times.

DEMO

Upvotes: 1

Related Questions