PHP, gets a string between two strings in a string of characters

Source: Internet
Author: User
Br-lan Link encap:ethernet HWaddr f0:b4:29:55:6c:2e
inet addr:192.168.8.9 bcast:192.168.8.255 mask:255.255.255.0
Inet6 ADDR:FDC1:B4AA:57BA::1/60 Scope:global
Inet6 ADDR:FE80::F2B4:29FF:FE55:6C2E/64 Scope:link
Inet6 ADDR:FD7B:7C0F:5360:4::1/62 Scope:global
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:6135 errors:0 dropped:0 overruns:0 frame:0
TX packets:7308 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:774045 (755.9 KiB) TX bytes:2084983 (1.9 MiB)

In the above string, I want to remove the IP address between the inet addr:192.168.8.9 bcast, can I ask you how to write the positive expression of PHP? Thank you.
$return _array is the string array above.
foreach ($return _array as $value) {//if (Preg_match ("/inet addr:/i", $value, $temp _array)) if (Preg_match ("\binet addr : \b.*\bbcast\b ", $value, $temp _array)) {echo '

';p rint_r ($temp _array);//var_dump ($temp _array);}}


Reply to discussion (solution)

Up, online and more.

if (Preg_match ("[0-9]{1,3}[.] [0-9] {1,3} [.] [0-9] {1,3} [.] [0-9] {1,3} ", $value, $temp _array))//Put in the code, this line has errors, use the tool to test OK. {echo '

';//print_r ($temp _array); Var_dump ($temp _array);}

\b[0-9]{1,3}[.] [0-9] {1,3} [.] [0-9] {1,3} [.] [0-9] {1,3}\b//if (Preg_match ("/\b[0-9]{1,3}[.] [0-9] {1,3} [.] [0-9] {1,3} [.] [0-9] {1,3}\b/", $value, $temp _array)) if (Preg_match ("/[0-9]{1,3}[. ") [0-9] {1,3} [.] [0-9] {1,3} [.] [0-9] {1,3}/", $value, $temp _array))//Ok{echo '

';//print_r ($temp _array); Var_dump ($temp _array);}

if (Preg_match ("/inet addr: (. +?) \s+bcast:/", $value, $temp _array))    {        echo '

'; Print_r ($temp _array); Var_dump ($temp _array); }

$s =<<< Txtbr-lan    Link encap:ethernet  HWaddr f0:b4:29:55:6c:2e            inet addr:192.168.8.9  bcast : 192.168.8.255  mask:255.255.255.0          inet6 addr:fdc1:b4aa:57ba::1/60 scope:global          inet6 addr:fe80::f2b4 : 29ff:fe55:6c2e/64 scope:link          inet6 addr:fd7b:7c0f:5360:4::1/62 scope:global up broadcast RUNNING MULTICAST  mtu:1500  Metric:1          RX packets:6135 errors:0 dropped:0 overruns:0 frame:0          TX packets:7308 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:774045 (755.9 KiB)  TX bytes:2084983 (1.9 MiB) txt;preg_ Match ('/(? <=ADDR:) [. \d]+/', $s, $m); Echo $m [0];
192.168.8.9
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.