简体   繁体   中英

RegEx with grep for Linux

Need some help at the command line running CentOS, but ultimately will be used on a Linux build. I've looked on the forum here and have tried a RegEx builder tool and I know the sytax for regex is right, but obviously it's not working.

options with the following have been tried in various combinations, not all together. ioFE

3 packets transmitted, 3 received, 0% packet loss, time 2002ms ping -c 3 192.168.0.113 | grep '(?<=received,)(.*)(?=,)'

I feel this should work, but not sure what is missing given what I know about regex. What am I doing wrong?

Updated. Two answers provided that both work:

ping -c 3 192.168.0.113 | grep -Po '(?<=received,)(.*)(?=,)'

ping -c 3 192.168.0.113 | grep -Po 'received,\\K[^,]+'

grep -P '(?<=received,)(.*)(?=,)'

You will have to enable -P mode for that regex to work.Your regex is correct. See here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM