DEV Community

Cook
Cook

Posted on

regexp lazy match

case

demo string is
/sbin/dhclient /xx -4 -d -nw -cf /run/dhclient/dhclient_eth1.conf -pf /run/dhclient/dhclient_eth1.pid

target

/run/dhclient/ is prefix path, it would change as os version changes, so get the /run/dhclient/

code

echo "/sbin/dhclient /xx -4 -d -nw -cf /run/dhclient/dhclient_eth1.conf -pf /run/dhclient/dhclient_eth1.pid" | grep -P "/\S*?eth1.conf " --color

resp

/run/dhclient/dhclient_eth1.conf

Top comments (0)